P. 1
Below and Beneath TDD: Test Last Development and Other Real-World Test Patterns

Below and Beneath TDD: Test Last Development and Other Real-World Test Patterns

|Views: 117|Likes:
Published by Best Tech Videos
This talk explores what makes Test Driven Development really work by showing what happens where the process breaks down, focusing on rapid feedback as the key to asuccessful test-driven process. It also creates a vocabulary for talking about malformed test processes.
This talk explores what makes Test Driven Development really work by showing what happens where the process breaks down, focusing on rapid feedback as the key to asuccessful test-driven process. It also creates a vocabulary for talking about malformed test processes.

More info:

Published by: Best Tech Videos on May 06, 2009
Copyright:Attribution Non-commercial

Availability:

Read on Scribd mobile: iPhone, iPad and Android.
download as PDF, TXT or read online from Scribd
See more
See less

05/27/2014

pdf

text

original

Below And Beneath TDD

Test-Last Development and other real world test patterns
Noel Rappin @noelrap Pathfinder Development pathf.com railsprescriptions.com

http://www.railsrx.com

TEST

REFACTOR

FAIL

PASS

CODE

R x

TEST

REFACTOR
Why does testing work?

FAIL

Why does testing fail?

PASS

CODE

R x

TEST

REFACTOR

FAIL

What does it mean for testing to “work”?

PASS

CODE

R x

TEST

REFACTOR
Improve effectiveness of team and quality of code

FAIL

NOT A perfect guarantee of code correctness

PASS

CODE

R x

TEST

FAIL

REFACTOR for me, tdd is about confidence & accountability & responsibility & design & reusability & portability & flexibility & testing & PASS trustworthiness & teamwork & initiative & flow & that's all i can think of at the moment.
-- Kent Beck CODE R x

TEST

REFACTOR
Accurate view of code Small, incremental steps

FAIL

Scaffold for change Focus for development

PASS

CODE

R x

TEST

REFACTOR

FAIL

What does it mean for testing to “fail”?

PASS

CODE

R x

TEST

REFACTOR

FAIL

Decrease efficiency and code quality

PASS

CODE

R x

TEST

REFACTOR
“It feels like there's a hidden door that everyone who tests has found and walked through... There are a bunch of us... PASS that would love to join the party, but don't know where to find the door.”

FAIL

CODE

R x

TEST

REFACTOR
If you are stuck in a window or banging your head against the wall, this will help you get to the door

FAIL

PASS

CODE

R x

TEST

REFACTOR

FAIL

PASS

CODE

R x

TEST

REFACTOR

FAIL

Test-Driven Development

PASS

CODE

R x

TEST

REFACTOR
AKA: Behavior-Driven Development

FAIL

or Test-First Programming

PASS

CODE

R x

TEST
TDD Code has:

REFACTOR

FAIL

small pieces high cohesion loose coupling minimal side-effects

PASS

CODE

R x

TEST

REFACTOR
☺Accurate view of code ☺Small, incremental steps

FAIL

☺Scaffold for change ☺Focus for development

PASS

CODE

R x

TEST

REFACTOR

FAIL

PASS

CODE

R x

TEST

FAIL

Lose the refactoring

PASS

CODE

R x

TEST

FAIL

Development, that happens to have tests

PASS

CODE

R x

TEST
Symptoms:

FAIL

Increased duplicaton in code. Long methods

PASS

CODE

R x

TEST
Benefits:

FAIL

May seem faster at first

PASS

CODE

R x

TEST
FAIL
Over time...

PASS

CODE

R x

TEST
☺Accurate view of code Small, incremental steps

FAIL

Scaffold for change ☺Focus for development

PASS

CODE

R x

TEST
FAIL
Fix by: Cleaning up your mess

PASS

CODE

R x

TEST

REFACTOR

FAIL

PASS

CODE

R x

TEST

REFACTOR

FAIL

PASS TEST CODE FAIL
R x

TEST

REFACTOR

assert_equal(nil, actual)

FAIL

assert_equal(4.314, actual)

PASS

TEST
actual = 4.314

CODE

FAIL
R x

TEST

REFACTOR
Data-Driven Testing or

FAIL

Using your program as a calculator

PASS TEST
R x

CODE

FAIL

TEST
Benefits:

REFACTOR

FAIL

Failed Test Guaranteed Value may be hard to calculate

PASS TEST
R x

CODE

FAIL

TEST
Pitfalls:

REFACTOR

FAIL

Can mask ignorance of domain Can lead to worse problems

PASS TEST

CODE

FAIL
R x

TEST

REFACTOR
Accurate view of code ☺Small, incremental steps

FAIL

☺Scaffold for change ☺Focus for development

PASS TEST
R x

CODE

FAIL

TEST

REFACTOR

assert_equal(nil, actual)

FAIL

assert_equal(4.314, actual)

PASS

TEST
actual = 4.314

CODE

FAIL
R x

CODE
actual = 4.314

REFACTOR

assert_equal(4.314, actual)

PASS

TEST

R x

CODE

REFACTOR
Test-Next Development aka Code-Driven Development

PASS

TEST

R x

CODE

Symptoms:

REFACTOR

No more failing tests Tweaking tests to match code Coverage drop

PASS

TEST

R x

CODE
Benefits:

REFACTOR
Useful when exploring Useful when testing views

PASS

TEST

R x

CODE
Pitfalls:

REFACTOR
Easily slides into worse patterns Hard to avoid coverage gaps

PASS

TEST

R x

CODE

REFACTOR
Accurate view of code ☺Small, incremental steps Scaffold for change Focus for development

PASS

TEST

R x

CODE

REFACTOR

Tautology Based Development

PASS

TEST

R x

CODE
Definition:

REFACTOR

Tests that can’t fail

PASS

TEST

R x

CODE
Symptoms:

REFACTOR
Bugs that should have been covered Mock object misuse

PASS

TEST

R x

CODE

REFACTOR
☹Accurate view of code ☺Small, incremental steps Scaffold for change ☹Focus for development

PASS

TEST

R x

CODE
Mitigation:

REFACTOR

Try to separate code assertions from application data

PASS

TEST

R x

CODE

REFACTOR

PASS

TEST

R x

CODE CODE CODE CODE CODE CODE CODE

REFACTOR

PASS

TEST

R x

CODE CODE CODE CODE CODE CODE CODE

REFACTOR

Test-Last Development

PASS

TEST

R x

CODE CODE CODE CODE CODE CODE CODE

REFACTOR
Symptoms: Significant coverage drop Uncovered bugs Harder to write tests

PASS

TEST

R x

CODE CODE CODE CODE CODE CODE CODE

REFACTOR
This is one way in which we talk past each other Unit tests ≠ TDD

PASS

TEST

R x

CODE CODE CODE CODE CODE CODE CODE

REFACTOR
Pitfall: Tests get more expensive Lower quality tests Programmer boredom

PASS

TEST

R x

CODE CODE CODE CODE CODE CODE CODE

REFACTOR
Needed when: Hitting corner case Dealing with legacy

PASS

TEST

R x

CODE REFACTOR CODE ☹Accurate view of code CODE ☹Small, incremental steps CODE Scaffold for change PASS CODE ☹Focus for development CODE CODE TEST
R x

CODE CODE CODE CODE CODE CODE CODE

REFACTOR
Escape by: Start the TDD process Don’t look back Catch up to legacy parts as you touch them

PASS

TEST

R x

CODE CODE CODE CODE CODE CODE CODE

REFACTOR

PASS

TEST

R x

CODE CODE CODE CODE CODE CODE CODE

REFACTOR

Run

TEST

R x

CODE CODE CODE CODE CODE CODE CODE

REFACTOR

Coverage Driven Development

Run

TEST

R x

CODE CODE CODE CODE CODE CODE CODE

REFACTOR

Symptom: Tests without assertions

Run

TEST

R x

CODE CODE CODE CODE CODE CODE CODE

REFACTOR
Why? Minimal approach to legacy Hard to reach code

Run

TEST

R x

CODE REFACTOR CODE ☹Accurate view of code CODE ☹Small, incremental steps CODE ☹Scaffold for change Run CODE ☹Focus for development CODE CODE TEST
R x

TEST

REFACTOR

FAIL

PASS

CODE

R x

TEST TEST TEST TEST TEST FAIL

REFACTOR

PASS

CODE

R x

TEST TEST TEST TEST TEST FAIL

REFACTOR

Lots of Test First Development

PASS

CODE

R x

TEST TEST TEST TEST TEST FAIL

REFACTOR
Symptom:

Lots of test failures at once during initial developmment

PASS

CODE

R x

TEST TEST TEST TEST TEST
Benefit:

REFACTOR

FAIL

Allows planning for future code

PASS

CODE

R x

TEST TEST TEST TEST TEST FAIL

REFACTOR
Cost: Loss of focus

PASS

Somewhat harder to write code against

CODE

R x

TEST TEST TEST TEST TEST
Middle Ground:

REFACTOR

FAIL

RSpec pending

PASS

CODE

R x

TEST REFACTOR TEST TEST ☺Accurate view of code TEST TEST
Small, incremental steps ☺Scaffold for change Focus for development

FAIL

PASS

CODE

R x

TEST

REFACTOR

FAIL

PASS

CODE

R x

SETUP
TEST FAIL CODE

REFACTOR

PASS

R x

SETUP
TEST FAIL CODE

REFACTOR

Setup Driven Development PASS

R x

SETUP
TEST FAIL

REFACTOR

Symptom:

Large, brittle setup methods Slow tests High-level tests

PASS

CODE

R x

SETUP
TEST
Costs:

REFACTOR

This is why people hate testing

PASS

FAIL CODE
R x

SETUP
TEST FAIL

REFACTOR

Accurate view of code

☹Small, incremental steps ☺Scaffold for change Focus for development

PASS

CODE

R x

SETUP
TEST
Escape by: Mock Objects

REFACTOR

PASS

FAIL

Real unit tests

CODE

R x

TEST

REFACTOR

FAIL

PASS

CODE

R x

TEST

REFACTOR
Another problem: End to end failures

FAIL

Lack of focus Expectation failures

PASS

CODE

R x

Cucumber

REFACTOR

TEST
A potential solution

PASS

FAIL CODE
R x

Cucumber

REFACTOR

TEST

Acceptance Test-Driven Development

PASS

FAIL CODE
R x

Cucumber

REFACTOR
Symptom:

TEST

You are writing acceptance tests

PASS

FAIL CODE
R x

Cucumber

REFACTOR
Costs:

TEST

Additional layer of test code, indirection

PASS

FAIL CODE
R x

Cucumber

REFACTOR
Benefits:

TEST

Increased focus, improved feedback

PASS

FAIL CODE
R x

Cucumber

REFACTOR

☺Accurate view of code

TEST

☺Small, incremental steps ☺Scaffold for change ☺Focus for development

PASS

FAIL CODE
R x

TEST

REFACTOR

FAIL

PASS

CODE

R x

TEST
And So:

REFACTOR

FAIL

PASS

CODE

R x

TEST

REFACTOR
Constant feedback and baby steps

FAIL

PASS

CODE

R x

TEST
Focus on what comes next

REFACTOR

FAIL

Failure Driven Development

PASS

CODE

R x

TEST
Good code has

REFACTOR
small pieces high cohesion loose coupling minimal side-effects

FAIL

PASS

CODE

R x

TEST

REFACTOR
Invisible cost of bugs or

FAIL

Done vs. “Done Done”

PASS

CODE

R x

TEST

REFACTOR

FAIL

Go write some tests!

PASS

CODE

R x

TEST

REFACTOR Rails Test Prescriptions
http://www.railsrx.com Pathfinder Development

FAIL

http://www.pathf.com http://www.pathf.com/blogs @noelrap @railsrx

PASS

BoF: 9PM CODE Wed Pavillion 9-10

R x

You're Reading a Free Preview

Download
scribd
/*********** DO NOT ALTER ANYTHING BELOW THIS LINE ! ************/ var s_code=s.t();if(s_code)document.write(s_code)//-->