Date post: | 15-Jul-2015 |
Category: |
Software |
Upload: | roberto-bettazzoni |
View: | 161 times |
Download: | 4 times |
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
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
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
道場型
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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()
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()
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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)
agile42 | We advise, train and coach companies building software | www.agile42.com | Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License
kata
型 (form)
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
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
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
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
agile42 | We advise, train and coach companies building software | www.agile42.com | Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License
Food for thoughts