tdd dojo - test driven development coding dojo

42
agile42 | We advise, train and coach companies building software | www.agile42.com | Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License T est Driven Development Dojo A safe way to be introduced to a powerful way of programming Roberto Bettazzoni

Upload: roberto-bettazzoni

Post on 15-Jul-2015

171 views

Category:

Software


4 download

TRANSCRIPT

Page 1: TDD Dojo - Test Driven Development Coding Dojo

agile42 | We advise, train and coach companies building software | www.agile42.com | Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License

Test Driven Development DojoA safe way to be introduced to a powerful way of programming !!Roberto Bettazzoni

Page 2: TDD Dojo - Test Driven Development Coding Dojo

agile42 | We advise, train and coach companies building software | www.agile42.com | Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License

About me

Agile Coach eXtreme Programming Trainer !>30 years of coding (and still proudly counting) [email protected] linkedin.com/in/robertobettazzoni @bettazzoni

Roberto Bettazzoni

Page 3: TDD Dojo - Test Driven Development Coding Dojo

agile42 | We advise, train and coach companies building software | www.agile42.com | Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License

T.D.D. Coder Dojo Agenda

• TDD in a very small nutshell • TDD Sempai demo • For each Kata (35 min.)

‣ Choose the Kata ‣ execute ‣ break (5 min.) ‣ StandUp

道場型

Page 4: TDD Dojo - Test Driven Development Coding Dojo

agile42 | We advise, train and coach companies building software | www.agile42.com | Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License agile42 | We advise, train and coach companies building software www.agile42.com | All rights reserved. Copyright © 2007 - 2010.

Test Driven Development

Page 5: TDD Dojo - Test Driven Development Coding Dojo

agile42 | We advise, train and coach companies building software | www.agile42.com | Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License

Test-Driven Development as Formula

TDD = ( Test First

+ Unit Testing

+ Refactoring )

* Baby Steps

Page 6: TDD Dojo - Test Driven Development Coding Dojo

agile42 | We advise, train and coach companies building software | www.agile42.com | Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License agile42 | We advise, train and coach companies building software www.agile42.com | All rights reserved. Copyright © 2007 - 2010.

Test First

Page 7: TDD Dojo - Test Driven Development Coding Dojo

agile42 | We advise, train and coach companies building software | www.agile42.com | Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License agile42 | We advise, train and coach companies building software www.agile42.com | All rights reserved. Copyright © 2007 - 2010.

Test First Programming

!

“Write a failing automated test before changing any code.”

!

Kent Beck, Extreme Programming Explained 2nd Ed. 2004

Page 8: TDD Dojo - Test Driven Development Coding Dojo

agile42 | We advise, train and coach companies building software | www.agile42.com | Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License agile42 | We advise, train and coach companies building software www.agile42.com | All rights reserved. Copyright © 2007 - 2010.

Unit Test

Page 9: TDD Dojo - Test Driven Development Coding Dojo

agile42 | We advise, train and coach companies building software | www.agile42.com | Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License

unit test

Method to verify isolated units of code

Page 10: TDD Dojo - Test Driven Development Coding Dojo

agile42 | We advise, train and coach companies building software | www.agile42.com | Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License

unit test

user

code

Acceptance Criteria test

Functional test

Unit test

Page 11: TDD Dojo - Test Driven Development Coding Dojo

agile42 | We advise, train and coach companies building software | www.agile42.com | Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License

unit test

Method to verify isolated units of code

Page 12: TDD Dojo - Test Driven Development Coding Dojo

agile42 | We advise, train and coach companies building software | www.agile42.com | Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License

unit test

Method to verify isolated units of code

Page 13: TDD Dojo - Test Driven Development Coding Dojo

agile42 | We advise, train and coach companies building software | www.agile42.com | Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License

unit test

assert condition

Page 14: TDD Dojo - Test Driven Development Coding Dojo

agile42 | We advise, train and coach companies building software | www.agile42.com | Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License

unit test

Method to verify isolated units of code

Page 15: TDD Dojo - Test Driven Development Coding Dojo

agile42 | We advise, train and coach companies building software | www.agile42.com | Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License

Test Isolation

B

D

C

A

Page 16: TDD Dojo - Test Driven Development Coding Dojo

agile42 | We advise, train and coach companies building software | www.agile42.com | Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License

Test Isolation

Run 4 tests: A, B, C, D

B

D

C

A

Page 17: TDD Dojo - Test Driven Development Coding Dojo

agile42 | We advise, train and coach companies building software | www.agile42.com | Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License

Test Isolation

B

D

C

A

Page 18: TDD Dojo - Test Driven Development Coding Dojo

agile42 | We advise, train and coach companies building software | www.agile42.com | Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License

Test Isolation

Run 3 tests: A, B, D

B

D

A

Page 19: TDD Dojo - Test Driven Development Coding Dojo

agile42 | We advise, train and coach companies building software | www.agile42.com | Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License

Test Isolation

Run 3 tests: D, A, B

B

D

A

Page 20: TDD Dojo - Test Driven Development Coding Dojo

agile42 | We advise, train and coach companies building software | www.agile42.com | Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License

unit test library

test()

Page 21: TDD Dojo - Test Driven Development Coding Dojo

agile42 | We advise, train and coach companies building software | www.agile42.com | Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License

unit test library

setUp() - test() - tearDown()

Page 22: TDD Dojo - Test Driven Development Coding Dojo

agile42 | We advise, train and coach companies building software | www.agile42.com | Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License

unit test

Method to verify isolated units of code

Page 23: TDD Dojo - Test Driven Development Coding Dojo

agile42 | We advise, train and coach companies building software | www.agile42.com | Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License

unit test - What is a unit of code?

Classes Methods Functions

Blocks of code

Page 24: TDD Dojo - Test Driven Development Coding Dojo

agile42 | We advise, train and coach companies building software | www.agile42.com | Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License

Code Isolation (or Unit Isolation)

B

D

C

A

Page 25: TDD Dojo - Test Driven Development Coding Dojo

agile42 | We advise, train and coach companies building software | www.agile42.com | Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License

Code Isolation (or Unit Isolation)

B

D

C

A

Page 26: TDD Dojo - Test Driven Development Coding Dojo

agile42 | We advise, train and coach companies building software | www.agile42.com | Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License agile42 | We advise, train and coach companies building software www.agile42.com | All rights reserved. Copyright © 2007 - 2010.

Code Refactoring

Page 27: TDD Dojo - Test Driven Development Coding Dojo

agile42 | We advise, train and coach companies building software | www.agile42.com | Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License

Refactoring

Changing existing code without changing its external behavior

Page 28: TDD Dojo - Test Driven Development Coding Dojo

agile42 | We advise, train and coach companies building software | www.agile42.com | Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License

Refactoring

Make your code better without changing its external behavior

Page 29: TDD Dojo - Test Driven Development Coding Dojo

agile42 | We advise, train and coach companies building software | www.agile42.com | Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License

Three Principles to Write Good Code

1. Find good names 2. Remove duplications 3. There is no third principle

Page 30: TDD Dojo - Test Driven Development Coding Dojo

agile42 | We advise, train and coach companies building software | www.agile42.com | Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License

Refactoring. The Sensei Words

Any fool can write code that a computer can understand.

Good programmers write code that humans can understand

Martin Fowler, Refactoring: Improving the Design of Existing Code, 1999 pag. 15

Page 31: TDD Dojo - Test Driven Development Coding Dojo

agile42 | We advise, train and coach companies building software | www.agile42.com | Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License agile42 | We advise, train and coach companies building software www.agile42.com | All rights reserved. Copyright © 2007 - 2010.

Baby Steps

Page 32: TDD Dojo - Test Driven Development Coding Dojo

agile42 | We advise, train and coach companies building software | www.agile42.com | Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License

Baby steps.

… proceed iteratively in baby steps — the shortest step that can be

appreciated in the right direction

Kent Beck, Extreme Programming Explained 2nd Ed. 2004

Page 33: TDD Dojo - Test Driven Development Coding Dojo

agile42 | We advise, train and coach companies building software | www.agile42.com | Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License agile42 | We advise, train and coach companies building software www.agile42.com | All rights reserved. Copyright © 2007 - 2010.

The TDD process

Unit tests suite pass

Add a unit testAdd a unit test

Write a unit test

Write the code

Refactor the code

Refactor the tests

Unit test pass

Unit test fails

Page 34: TDD Dojo - Test Driven Development Coding Dojo

agile42 | We advise, train and coach companies building software | www.agile42.com | Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License agile42 | We advise, train and coach companies building software www.agile42.com | All rights reserved. Copyright © 2007 - 2010.

The TDD process from the Functional Tests

Add a functional testRun the test & check failure

Run all functional tests see all pass

!

Refactor the

Design

Page 35: TDD Dojo - Test Driven Development Coding Dojo

agile42 | We advise, train and coach companies building software | www.agile42.com | Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License agile42 | We advise, train and coach companies building software www.agile42.com | All rights reserved. Copyright © 2007 - 2010.

Welcome to the coding dojo

Page 36: TDD Dojo - Test Driven Development Coding Dojo

agile42 | We advise, train and coach companies building software | www.agile42.com | Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License

dojo

道場 (place of the way)

Page 37: TDD Dojo - Test Driven Development Coding Dojo

agile42 | We advise, train and coach companies building software | www.agile42.com | Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License

kata

型 (form)

Page 38: TDD Dojo - Test Driven Development Coding Dojo

agile42 | We advise, train and coach companies building software | www.agile42.com | Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License

Dojo Kun (the dojo rules)

At the Dojo one can’t discuss a form without code, and one can’t show code without tests. It is a design training place, where it is acknowledged that “the code is the design” and that code without tests simply doesn’t exist. Emily Bache, The Coding Dojo Handbook, 2012 (translated from Christophe Thibaut, Laurent Bossavit’s blog, 2005)

You are here to practice, not to build something No output is required, neither logging or tracing activities Every aspect of the kata (design, UI …) is in your hands

Page 39: TDD Dojo - Test Driven Development Coding Dojo

agile42 | We advise, train and coach companies building software | www.agile42.com | Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License

Sempai Demo

Let’s start the Sempai TDD Demo

Page 40: TDD Dojo - Test Driven Development Coding Dojo

agile42 | We advise, train and coach companies building software | www.agile42.com | Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License agile42 | We advise, train and coach companies building software www.agile42.com | All rights reserved. Copyright © 2007 - 2010.

Coding Dojo retrospective

Page 41: TDD Dojo - Test Driven Development Coding Dojo

agile42 | We advise, train and coach companies building software | www.agile42.com | Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License

TDD ALL CODE IS GUILTY

UNTIL PROVEN INNOCENT

Page 42: TDD Dojo - Test Driven Development Coding Dojo

agile42 | We advise, train and coach companies building software | www.agile42.com | Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License

Food for thoughts