Below And Beneath Tdd Test Last Development And Other Real World Test Patterns Presentation

90
Below And Beneath TDD Test-Last Development and other real world test patterns Noel Rappin @noelrap Pathfinder Development pathf.com railsprescriptions.com

Transcript of Below And Beneath Tdd Test Last Development And Other Real World Test Patterns Presentation

Page 1: Below And Beneath Tdd  Test Last Development And Other Real World Test Patterns Presentation

Below And Beneath TDD

Test-Last Development and other real world test patterns

Noel Rappin@noelrap

Pathfinder Developmentpathf.com

railsprescriptions.com

Page 2: Below And Beneath Tdd  Test Last Development And Other Real World Test Patterns Presentation

http://www.railsrx.com

Page 3: Below And Beneath Tdd  Test Last Development And Other Real World Test Patterns Presentation

Rx

TEST

FAIL

CODE

REFACTOR

PASS

Page 4: Below And Beneath Tdd  Test Last Development And Other Real World Test Patterns Presentation

Rx

TEST

FAIL

CODE

REFACTOR

PASS

Why does testing work?

Why does testing fail?

Page 5: Below And Beneath Tdd  Test Last Development And Other Real World Test Patterns Presentation

Rx

TEST

FAIL

CODE

REFACTOR

PASSWhat does it mean for

testing to “work”?

Page 6: Below And Beneath Tdd  Test Last Development And Other Real World Test Patterns Presentation

Rx

TEST

FAIL

CODE

REFACTOR

PASS

Improve effectiveness of team and

quality of code

NOT

A perfect guarantee ofcode correctness

Page 7: Below And Beneath Tdd  Test Last Development And Other Real World Test Patterns Presentation

Rx

TEST

FAIL

CODE

REFACTOR

PASS

for me, tdd is about confidence &

accountability & responsibility & design &

reusability & portability & flexibility & testing & trustworthiness &

teamwork & initiative & flow & that's all i can

think of at the moment.

-- Kent Beck

Page 8: Below And Beneath Tdd  Test Last Development And Other Real World Test Patterns Presentation

Rx

TEST

FAIL

CODE

REFACTOR

PASS

Accurate view of code

Small, incremental steps

Scaffold for change

Focus for development

Page 9: Below And Beneath Tdd  Test Last Development And Other Real World Test Patterns Presentation

Rx

TEST

FAIL

CODE

REFACTOR

PASSWhat does it mean for

testing to “fail”?

Page 10: Below And Beneath Tdd  Test Last Development And Other Real World Test Patterns Presentation

Rx

TEST

FAIL

CODE

REFACTOR

PASSDecrease efficiency and

code quality

Page 11: Below And Beneath Tdd  Test Last Development And Other Real World Test Patterns Presentation

Rx

TEST

FAIL

CODE

REFACTOR

PASS

“It feels like there's a hidden door that everyone who tests has found and

walked through... There are a bunch of us...that would love to join

the party, but don't know where to find

the door.”

Page 12: Below And Beneath Tdd  Test Last Development And Other Real World Test Patterns Presentation

Rx

TEST

FAIL

CODE

REFACTOR

PASS

If you are stuck in a window or banging your head against the wall,

this will helpyou get to the door

Page 13: Below And Beneath Tdd  Test Last Development And Other Real World Test Patterns Presentation

Rx

TEST

FAIL

CODE

REFACTOR

PASS

Page 14: Below And Beneath Tdd  Test Last Development And Other Real World Test Patterns Presentation

Rx

TEST

FAIL

CODE

REFACTOR

PASSTest-Driven

Development

Page 15: Below And Beneath Tdd  Test Last Development And Other Real World Test Patterns Presentation

Rx

TEST

FAIL

CODE

REFACTOR

PASS

AKA: Behavior-DrivenDevelopment

or

Test-FirstProgramming

Page 16: Below And Beneath Tdd  Test Last Development And Other Real World Test Patterns Presentation

Rx

TEST

FAIL

CODE

REFACTOR

PASS

TDD Code has:

small pieceshigh cohesionloose coupling

minimal side-effects

Page 17: Below And Beneath Tdd  Test Last Development And Other Real World Test Patterns Presentation

Rx

TEST

FAIL

CODE

REFACTOR

PASS

☺Accurate view of code

☺Small, incremental steps

☺Scaffold for change

☺Focus for development

Page 18: Below And Beneath Tdd  Test Last Development And Other Real World Test Patterns Presentation

Rx

TEST

FAIL

CODE

REFACTOR

PASS

Page 19: Below And Beneath Tdd  Test Last Development And Other Real World Test Patterns Presentation

Rx

TEST

FAIL

CODE

PASSLose the refactoring

Page 20: Below And Beneath Tdd  Test Last Development And Other Real World Test Patterns Presentation

Rx

TEST

FAIL

CODE

PASSDevelopment, that

happensto have tests

Page 21: Below And Beneath Tdd  Test Last Development And Other Real World Test Patterns Presentation

Rx

TEST

FAIL

CODE

PASS

Symptoms:

Increased duplicaton in code.

Long methods

Page 22: Below And Beneath Tdd  Test Last Development And Other Real World Test Patterns Presentation

Rx

TEST

FAIL

CODE

PASS

Benefits:

May seem faster at first

Page 23: Below And Beneath Tdd  Test Last Development And Other Real World Test Patterns Presentation

Rx

TEST

FAIL

CODE

PASSOver time...

Page 24: Below And Beneath Tdd  Test Last Development And Other Real World Test Patterns Presentation

Rx

TEST

FAIL

CODE

PASS

☺Accurate view of code

Small, incremental steps

Scaffold for change

☺Focus for development

Page 25: Below And Beneath Tdd  Test Last Development And Other Real World Test Patterns Presentation

Rx

TEST

FAIL

CODE

PASSFix by:

Cleaning up your mess

Page 26: Below And Beneath Tdd  Test Last Development And Other Real World Test Patterns Presentation

Rx

TEST

FAIL

CODE

REFACTOR

PASS

Page 27: Below And Beneath Tdd  Test Last Development And Other Real World Test Patterns Presentation

Rx

TEST

FAIL

CODE

REFACTOR

PASS

TEST

FAIL

Page 28: Below And Beneath Tdd  Test Last Development And Other Real World Test Patterns Presentation

Rx

TEST

FAIL

CODE

REFACTOR

PASS

TEST

FAIL

assert_equal(nil, actual)

actual = 4.314

assert_equal(4.314, actual)

Page 29: Below And Beneath Tdd  Test Last Development And Other Real World Test Patterns Presentation

Rx

TEST

FAIL

CODE

REFACTOR

PASS

TEST

FAIL

Data-Driven Testing

or

Using your programas a calculator

Page 30: Below And Beneath Tdd  Test Last Development And Other Real World Test Patterns Presentation

Rx

TEST

FAIL

CODE

REFACTOR

PASS

TEST

FAIL

Benefits:

Failed Test Guaranteed

Value may be hard to calculate

Page 31: Below And Beneath Tdd  Test Last Development And Other Real World Test Patterns Presentation

Rx

TEST

FAIL

CODE

REFACTOR

PASS

TEST

FAIL

Pitfalls:

Can mask ignoranceof domain

Can lead to worseproblems

Page 32: Below And Beneath Tdd  Test Last Development And Other Real World Test Patterns Presentation

Rx

TEST

FAIL

CODE

REFACTOR

PASS

TEST

FAIL

Accurate view of code

☺Small, incremental steps

☺Scaffold for change

☺Focus for development

Page 33: Below And Beneath Tdd  Test Last Development And Other Real World Test Patterns Presentation

Rx

TEST

FAIL

CODE

REFACTOR

PASS

TEST

FAIL

assert_equal(nil, actual)

actual = 4.314

assert_equal(4.314, actual)

Page 34: Below And Beneath Tdd  Test Last Development And Other Real World Test Patterns Presentation

Rx

CODE REFACTOR

PASS

TEST

actual = 4.314

assert_equal(4.314, actual)

Page 35: Below And Beneath Tdd  Test Last Development And Other Real World Test Patterns Presentation

Rx

TEST

CODE REFACTOR

PASS

Test-Next Development

aka

Code-Driven Development

Page 36: Below And Beneath Tdd  Test Last Development And Other Real World Test Patterns Presentation

Rx

TEST

CODE REFACTOR

PASS

Symptoms:

No more failing tests

Tweaking tests to match code

Coverage drop

Page 37: Below And Beneath Tdd  Test Last Development And Other Real World Test Patterns Presentation

Rx

TEST

CODE REFACTOR

PASS

Benefits:

Useful when exploring

Useful when testingviews

Page 38: Below And Beneath Tdd  Test Last Development And Other Real World Test Patterns Presentation

Rx

TEST

CODE REFACTOR

PASS

Pitfalls:

Easily slides into worsepatterns

Hard to avoidcoverage gaps

Page 39: Below And Beneath Tdd  Test Last Development And Other Real World Test Patterns Presentation

Rx

TEST

CODE REFACTOR

PASS

Accurate view of code

☺Small, incremental steps

Scaffold for change

Focus for development

Page 40: Below And Beneath Tdd  Test Last Development And Other Real World Test Patterns Presentation

Rx

TEST

CODE REFACTOR

PASSTautology Based

Development

Page 41: Below And Beneath Tdd  Test Last Development And Other Real World Test Patterns Presentation

Rx

TEST

CODE REFACTOR

PASS

Definition:

Tests that can’tfail

Page 42: Below And Beneath Tdd  Test Last Development And Other Real World Test Patterns Presentation

Rx

TEST

CODE REFACTOR

PASS

Symptoms:

Bugs that should have been covered

Mock objectmisuse

Page 43: Below And Beneath Tdd  Test Last Development And Other Real World Test Patterns Presentation

Rx

TEST

CODE REFACTOR

PASS

☹Accurate view of code

☺Small, incremental steps

Scaffold for change

☹Focus for development

Page 44: Below And Beneath Tdd  Test Last Development And Other Real World Test Patterns Presentation

Rx

TEST

CODE REFACTOR

PASS

Mitigation:

Try to separatecode assertions from application

data

Page 45: Below And Beneath Tdd  Test Last Development And Other Real World Test Patterns Presentation

Rx

TEST

CODE REFACTOR

PASS

Page 46: Below And Beneath Tdd  Test Last Development And Other Real World Test Patterns Presentation

Rx

TEST

CODE REFACTOR

PASS

CODE

CODE

CODE

CODE

CODE

CODE

Page 47: Below And Beneath Tdd  Test Last Development And Other Real World Test Patterns Presentation

Rx

TEST

CODE REFACTOR

PASS

CODE

CODE

CODE

CODE

CODE

CODE

Test-Last Development

Page 48: Below And Beneath Tdd  Test Last Development And Other Real World Test Patterns Presentation

Rx

TEST

CODE REFACTOR

PASS

CODE

CODE

CODE

CODE

CODE

CODE

Symptoms:

Significant coverage drop

Uncovered bugs

Harder to write tests

Page 49: Below And Beneath Tdd  Test Last Development And Other Real World Test Patterns Presentation

Rx

TEST

CODE REFACTOR

PASS

CODE

CODE

CODE

CODE

CODE

CODE

This is one way in which we talk past each other

Unit tests ≠ TDD

Page 50: Below And Beneath Tdd  Test Last Development And Other Real World Test Patterns Presentation

Rx

TEST

CODE REFACTOR

PASS

CODE

CODE

CODE

CODE

CODE

CODE

Pitfall:

Tests get moreexpensive

Lower quality tests

Programmer boredom

Page 51: Below And Beneath Tdd  Test Last Development And Other Real World Test Patterns Presentation

Rx

TEST

CODE REFACTOR

PASS

CODE

CODE

CODE

CODE

CODE

CODE

Needed when:

Hitting corner case

Dealing with legacy

Page 52: Below And Beneath Tdd  Test Last Development And Other Real World Test Patterns Presentation

Rx

TEST

CODE REFACTOR

PASS

CODE

CODE

CODE

CODE

CODE

CODE

☹Accurate view of code

☹Small, incremental steps

Scaffold for change

☹Focus for development

Page 53: Below And Beneath Tdd  Test Last Development And Other Real World Test Patterns Presentation

Rx

TEST

CODE REFACTOR

PASS

CODE

CODE

CODE

CODE

CODE

CODE

Escape by:

Start the TDD process

Don’t look back

Catch up to legacyparts as you touch

them

Page 54: Below And Beneath Tdd  Test Last Development And Other Real World Test Patterns Presentation

Rx

TEST

CODE REFACTOR

PASS

CODE

CODE

CODE

CODE

CODE

CODE

Page 55: Below And Beneath Tdd  Test Last Development And Other Real World Test Patterns Presentation

Rx

TEST

CODE REFACTOR

Run

CODE

CODE

CODE

CODE

CODE

CODE

Page 56: Below And Beneath Tdd  Test Last Development And Other Real World Test Patterns Presentation

Rx

TEST

CODE REFACTOR

Run

CODE

CODE

CODE

CODE

CODE

CODE

Coverage Driven Development

Page 57: Below And Beneath Tdd  Test Last Development And Other Real World Test Patterns Presentation

Rx

TEST

CODE REFACTOR

Run

CODE

CODE

CODE

CODE

CODE

CODE

Symptom:

Tests without assertions

Page 58: Below And Beneath Tdd  Test Last Development And Other Real World Test Patterns Presentation

Rx

TEST

CODE REFACTOR

Run

CODE

CODE

CODE

CODE

CODE

CODE

Why?

Minimal approach to legacy

Hard to reach code

Page 59: Below And Beneath Tdd  Test Last Development And Other Real World Test Patterns Presentation

Rx

TEST

CODE REFACTOR

Run

CODE

CODE

CODE

CODE

CODE

CODE

☹Accurate view of code

☹Small, incremental steps

☹Scaffold for change

☹Focus for development

Page 60: Below And Beneath Tdd  Test Last Development And Other Real World Test Patterns Presentation

Rx

TEST

FAIL

CODE

REFACTOR

PASS

Page 61: Below And Beneath Tdd  Test Last Development And Other Real World Test Patterns Presentation

Rx

TEST

FAIL

CODE

REFACTOR

PASS

TESTTEST

TESTTEST

Page 62: Below And Beneath Tdd  Test Last Development And Other Real World Test Patterns Presentation

Rx

TEST

FAIL

CODE

REFACTOR

PASS

TESTTEST

TESTTEST

Lots of Test First Development

Page 63: Below And Beneath Tdd  Test Last Development And Other Real World Test Patterns Presentation

Rx

TEST

FAIL

CODE

REFACTOR

PASS

TESTTEST

TESTTESTSymptom:

Lots of test failures atonce during initial developmment

Page 64: Below And Beneath Tdd  Test Last Development And Other Real World Test Patterns Presentation

Rx

TEST

FAIL

CODE

REFACTOR

PASS

TESTTEST

TESTTESTBenefit:

Allows planning for future code

Page 65: Below And Beneath Tdd  Test Last Development And Other Real World Test Patterns Presentation

Rx

TEST

FAIL

CODE

REFACTOR

PASS

TESTTEST

TESTTEST Cost:

Loss of focus

Somewhat harder towrite code against

Page 66: Below And Beneath Tdd  Test Last Development And Other Real World Test Patterns Presentation

Rx

TEST

FAIL

CODE

REFACTOR

PASS

TESTTEST

TESTTEST

Middle Ground:

RSpec pending

Page 67: Below And Beneath Tdd  Test Last Development And Other Real World Test Patterns Presentation

Rx

TEST

FAIL

CODE

REFACTOR

PASS

TESTTEST

TESTTEST☺Accurate view of code

Small, incremental steps

☺Scaffold for change

Focus for development

Page 68: Below And Beneath Tdd  Test Last Development And Other Real World Test Patterns Presentation

Rx

TEST

FAIL

CODE

REFACTOR

PASS

Page 69: Below And Beneath Tdd  Test Last Development And Other Real World Test Patterns Presentation

Rx

TEST

FAIL

CODE

REFACTOR

PASS

SETUP

Page 70: Below And Beneath Tdd  Test Last Development And Other Real World Test Patterns Presentation

Rx

TEST

FAIL

CODE

REFACTOR

PASS

SETUP

Setup Driven Development

Page 71: Below And Beneath Tdd  Test Last Development And Other Real World Test Patterns Presentation

Rx

TEST

FAIL

CODE

REFACTOR

PASS

SETUPSymptom:

Large, brittle setup methods

Slow tests

High-level tests

Page 72: Below And Beneath Tdd  Test Last Development And Other Real World Test Patterns Presentation

Rx

TEST

FAIL

CODE

REFACTOR

PASS

SETUPCosts:

This is why people hate testing

Page 73: Below And Beneath Tdd  Test Last Development And Other Real World Test Patterns Presentation

Rx

TEST

FAIL

CODE

REFACTOR

PASS

SETUPAccurate view of code

☹Small, incremental steps

☺Scaffold for change

Focus for development

Page 74: Below And Beneath Tdd  Test Last Development And Other Real World Test Patterns Presentation

Rx

TEST

FAIL

CODE

REFACTOR

PASS

SETUPEscape by:

Mock Objects

Real unit tests

Page 75: Below And Beneath Tdd  Test Last Development And Other Real World Test Patterns Presentation

Rx

TEST

FAIL

CODE

REFACTOR

PASS

Page 76: Below And Beneath Tdd  Test Last Development And Other Real World Test Patterns Presentation

Rx

TEST

FAIL

CODE

REFACTOR

PASS

Another problem:

End to end failures

Lack of focus

Expectation failures

Page 77: Below And Beneath Tdd  Test Last Development And Other Real World Test Patterns Presentation

Rx

TEST

FAIL

CODE

REFACTOR

PASS

Cucumber

A potential solution

Page 78: Below And Beneath Tdd  Test Last Development And Other Real World Test Patterns Presentation

Rx

TEST

FAIL

CODE

REFACTOR

PASS

Cucumber

Acceptance Test-DrivenDevelopment

Page 79: Below And Beneath Tdd  Test Last Development And Other Real World Test Patterns Presentation

Rx

TEST

FAIL

CODE

REFACTOR

PASS

Cucumber

Symptom:

You are writing acceptance tests

Page 80: Below And Beneath Tdd  Test Last Development And Other Real World Test Patterns Presentation

Rx

TEST

FAIL

CODE

REFACTOR

PASS

Cucumber

Costs:

Additional layer of test code, indirection

Page 81: Below And Beneath Tdd  Test Last Development And Other Real World Test Patterns Presentation

Rx

TEST

FAIL

CODE

REFACTOR

PASS

Cucumber

Benefits:

Increased focus, improved feedback

Page 82: Below And Beneath Tdd  Test Last Development And Other Real World Test Patterns Presentation

Rx

TEST

FAIL

CODE

REFACTOR

PASS

Cucumber

☺Accurate view of code

☺Small, incremental steps

☺Scaffold for change

☺Focus for development

Page 83: Below And Beneath Tdd  Test Last Development And Other Real World Test Patterns Presentation

Rx

TEST

FAIL

CODE

REFACTOR

PASS

Page 84: Below And Beneath Tdd  Test Last Development And Other Real World Test Patterns Presentation

Rx

TEST

FAIL

CODE

REFACTOR

PASS

And So:

Page 85: Below And Beneath Tdd  Test Last Development And Other Real World Test Patterns Presentation

Rx

TEST

FAIL

CODE

REFACTOR

PASS

Constant feedbackand

baby steps

Page 86: Below And Beneath Tdd  Test Last Development And Other Real World Test Patterns Presentation

Rx

TEST

FAIL

CODE

REFACTOR

PASS

Focus on what comes next

Failure Driven Development

Page 87: Below And Beneath Tdd  Test Last Development And Other Real World Test Patterns Presentation

Rx

TEST

FAIL

CODE

REFACTOR

PASS

Good code has

small pieceshigh cohesionloose coupling

minimal side-effects

Page 88: Below And Beneath Tdd  Test Last Development And Other Real World Test Patterns Presentation

Rx

TEST

FAIL

CODE

REFACTOR

PASS

Invisible cost of bugs

or

Done vs. “Done Done”

Page 89: Below And Beneath Tdd  Test Last Development And Other Real World Test Patterns Presentation

Rx

TEST

FAIL

CODE

REFACTOR

PASSGo write

some tests!

Page 90: Below And Beneath Tdd  Test Last Development And Other Real World Test Patterns Presentation

Rx

TEST

FAIL

CODE

REFACTOR

PASS

Rails Test Prescriptions

http://www.railsrx.com

Pathfinder Development

http://www.pathf.comhttp://www.pathf.com/blogs

@noelrap @railsrx

BoF: 9PM Wed Pavillion 9-10