Coding Dojo:
TDD as if You Meant It
Agile Testing Days 2013

Peter Kofler, ‘Code Cop’
@codecopkofler
www.code-cop.org
Copyright Peter Kofler, licensed under CC-BY.
PETER KOFLER, CODE-COP.ORG

FANATIC ABOUT CODE QUALITY

Peter Kofler
• Software Developer
for 14 years
• “fanatic about
code quality”
• I help development teams to do it right
• Pair Programming #CodeCopTour
Expectations?
PETER KOFLER, CODE-COP.ORG

FANATIC ABOUT CODE QUALITY

Coding Dojo Mindset
●

Safe place outside
work

●

We are here to learn

●

Need to slow down

●

Focus on doing it right

●

Collaborative Game
PETER KOFLER, CODE-COP.ORG

FANATIC ABOUT CODE QUALITY

Dojo Structure
●

Introduction 15'

●

Coding 30'

●

Interim (Retrospective) 15'

●

Break 25'

●

Coding 45'

●

Retrospective 15'
PETER KOFLER, CODE-COP.ORG

FANATIC ABOUT CODE QUALITY

TDD Skills
●

Driving Development with Tests 

●

Designing Test Cases

●

Designing Clean Code

●

Refactoring Safely
PETER KOFLER, CODE-COP.ORG

FANATIC ABOUT CODE QUALITY

TDD should be...
●

Add a test

●

See it fail

●

Add code to make all tests pass

●

Refactor mercilessly

●

Repeat
PETER KOFLER, CODE-COP.ORG

FANATIC ABOUT CODE QUALITY

… but often is
●

Think up design

●

Write some tests that verify the design

●

Write full implementation

●

Test, debug, test, debug, test, debug, …

●

Add TODO to refactor later
PETER KOFLER, CODE-COP.ORG

FANATIC ABOUT CODE QUALITY

TDD as if You Meant It
PETER KOFLER, CODE-COP.ORG

FANATIC ABOUT CODE QUALITY

Rules
Exactly one, simplest failing test
●
Least code possible to pass failing test
●
Add code only to test methods
●
When duplication is spotted
●
Extract non-test methods (extract method)
●
New classes only as target for “move method”
●
Refactor as required
●
PETER KOFLER, CODE-COP.ORG

FANATIC ABOUT CODE QUALITY

Assignment
PETER KOFLER, CODE-COP.ORG

FANATIC ABOUT CODE QUALITY

Tic-Tac-Toe
●

http://en.wikipedia.org/wiki/Tic-tac-toe

●

Board 3x3

●

X plays first, O plays second

●

Check if/who is winner
Don't Focus on
Getting it Done.
F0cus on Doing
It Perfectly.
→Practice
PETER KOFLER, CODE-COP.ORG

FANATIC ABOUT CODE QUALITY

Closing Circle
●

What did you learn today?

●

What surprised you today?

●

What will you do
differently in the
future?
PETER KOFLER, CODE-COP.ORG

FANATIC ABOUT CODE QUALITY

Please evaluate my presentation
using the AgileTD Mobile App at
www.touchmyconference.com/ATD2013

I appreciate your feedback.
PETER KOFLER, CODE-COP.ORG

FANATIC ABOUT CODE QUALITY

Peter Kofler
@codecopkofler
www.code-cop.org

Kata by

Keith Braithwaite
@keithb_b
http://cumulative-hypotheses.org/2011/08/30/tdd-as-if-you-meant-it/
PETER KOFLER, CODE-COP.ORG

FANATIC ABOUT CODE QUALITY

CC Images
●

Dojo http://www.flickr.com/photos/49715404@N00/3267627038/

●

Todos http://www.flickr.com/photos/kylesteeddesign/3724074594/

●

Signs http://www.flickr.com/photos/rwp-roger/7689114246/

●

Game http://www.flickr.com/photos/benclinch/476855843/

●

Wants you http://www.flickr.com/photos/shutter/105497713/

TDD as if You Meant It (2013)

  • 1.
    Coding Dojo: TDD asif You Meant It Agile Testing Days 2013 Peter Kofler, ‘Code Cop’ @codecopkofler www.code-cop.org Copyright Peter Kofler, licensed under CC-BY.
  • 2.
    PETER KOFLER, CODE-COP.ORG FANATICABOUT CODE QUALITY Peter Kofler • Software Developer for 14 years • “fanatic about code quality” • I help development teams to do it right • Pair Programming #CodeCopTour
  • 3.
  • 4.
    PETER KOFLER, CODE-COP.ORG FANATICABOUT CODE QUALITY Coding Dojo Mindset ● Safe place outside work ● We are here to learn ● Need to slow down ● Focus on doing it right ● Collaborative Game
  • 5.
    PETER KOFLER, CODE-COP.ORG FANATICABOUT CODE QUALITY Dojo Structure ● Introduction 15' ● Coding 30' ● Interim (Retrospective) 15' ● Break 25' ● Coding 45' ● Retrospective 15'
  • 6.
    PETER KOFLER, CODE-COP.ORG FANATICABOUT CODE QUALITY TDD Skills ● Driving Development with Tests  ● Designing Test Cases ● Designing Clean Code ● Refactoring Safely
  • 7.
    PETER KOFLER, CODE-COP.ORG FANATICABOUT CODE QUALITY TDD should be... ● Add a test ● See it fail ● Add code to make all tests pass ● Refactor mercilessly ● Repeat
  • 8.
    PETER KOFLER, CODE-COP.ORG FANATICABOUT CODE QUALITY … but often is ● Think up design ● Write some tests that verify the design ● Write full implementation ● Test, debug, test, debug, test, debug, … ● Add TODO to refactor later
  • 9.
    PETER KOFLER, CODE-COP.ORG FANATICABOUT CODE QUALITY TDD as if You Meant It
  • 10.
    PETER KOFLER, CODE-COP.ORG FANATICABOUT CODE QUALITY Rules Exactly one, simplest failing test ● Least code possible to pass failing test ● Add code only to test methods ● When duplication is spotted ● Extract non-test methods (extract method) ● New classes only as target for “move method” ● Refactor as required ●
  • 11.
    PETER KOFLER, CODE-COP.ORG FANATICABOUT CODE QUALITY Assignment
  • 12.
    PETER KOFLER, CODE-COP.ORG FANATICABOUT CODE QUALITY Tic-Tac-Toe ● http://en.wikipedia.org/wiki/Tic-tac-toe ● Board 3x3 ● X plays first, O plays second ● Check if/who is winner
  • 13.
    Don't Focus on Gettingit Done. F0cus on Doing It Perfectly.
  • 14.
  • 15.
    PETER KOFLER, CODE-COP.ORG FANATICABOUT CODE QUALITY Closing Circle ● What did you learn today? ● What surprised you today? ● What will you do differently in the future?
  • 16.
    PETER KOFLER, CODE-COP.ORG FANATICABOUT CODE QUALITY Please evaluate my presentation using the AgileTD Mobile App at www.touchmyconference.com/ATD2013 I appreciate your feedback.
  • 17.
    PETER KOFLER, CODE-COP.ORG FANATICABOUT CODE QUALITY Peter Kofler @codecopkofler www.code-cop.org Kata by Keith Braithwaite @keithb_b http://cumulative-hypotheses.org/2011/08/30/tdd-as-if-you-meant-it/
  • 18.
    PETER KOFLER, CODE-COP.ORG FANATICABOUT CODE QUALITY CC Images ● Dojo http://www.flickr.com/photos/49715404@N00/3267627038/ ● Todos http://www.flickr.com/photos/kylesteeddesign/3724074594/ ● Signs http://www.flickr.com/photos/rwp-roger/7689114246/ ● Game http://www.flickr.com/photos/benclinch/476855843/ ● Wants you http://www.flickr.com/photos/shutter/105497713/