Folding the Design Space Case Study: TDD with Specification by Example
www.mozaicworks.com
Me
Adi BolboacProgrammerOrganizational & TechnicalTrainer & Coach
www.mozaicworks.com
TDD
www.mozaicworks.com
TDD As if you Meant It
www.mozaicworks.com
Write exactly one failing test
Make the test pass by writing implementation code in the test method
Create a new implementation method by: Extracting implementation code to a new method in the test class
Moving implementation code into an existing implementation method from the test class
Create implementation classes to provide a destination for extracting a method in the test class
When necessary move implementation methods into implementation classes
Refactor as required
Classicist TDD
Prefer writing state tests
Usually start bottom-up
Do not use test doubles unless necessary
www.mozaicworks.com
Mockist TDD
Prefer writing collaboration tests
Usually start top-down
Always test in isolation
Use only one mock at a time for a test
www.mozaicworks.com
Specification by Example
[...]Defining requirements and business-oriented functional tests for software products based on capturing and illustrating requirements using realistic examples instead of abstract statements.
[http://en.wikipedia.org/wiki/Specification_by_example]
www.mozaicworks.com
Problem: Conway's Game of Life
www.mozaicworks.com
Having an infinite 2D orthogonal universeBeing given an initial generation called a seed
The following rules are applied simultaneously
A live cell having less than 2 live neighbors diesA live cell having 2 or 3 live neighbors lives A live cell having more than 3 neighbors diesA dead cell having 3 neighbors becomes alive
Purposes of the session
I care about specifications and I don't care about representation
Have the cleanest design possible with highly cohesive structures
Use real life examples as specifications
www.mozaicworks.com
Incremental design
I want to introduce one notion at a time.
www.mozaicworks.com
The visible notions from Conway's Game of Life
CellBoard
Universe
Life state
Generation
Set of rules
Neighbourhood
www.mozaicworks.com
Start with Incremental design
Simplify the problem
Introduce only one notion at a time
Find the main functionality: Tick()
www.mozaicworks.com
Question
What would the simplest first step be?
www.mozaicworks.com
Option: Slider Gun
www.mozaicworks.com
www.mozaicworks.com
Requirements
From real life examples
Specification by Example
www.mozaicworks.com
Step 1
empty universe => empty universe
www.mozaicworks.com
Step 1
empty universe => empty universe
www.mozaicworks.com
Step 1
empty universe => empty universe
www.mozaicworks.com
Step 1
empty universe => empty universe
www.mozaicworks.com
www.mozaicworks.com
Conclusions
When the solution is less known TDD as if you meant it is useful
Bottom-up TDD is useful to grow a system
You need to refactor more with TDD bottom-up
The design increments are smaller bottom-up
www.mozaicworks.com
Thank you!
www.mozaicworks.com
References
http://4.bp.blogspot.com/_9kQQgQD35rY/SaV5p8YBGhI/AAAAAAAAAkg/HOvlhIo7yGI/s1600-h/06_Red_Green_Refactor.JPG
http://upload.wikimedia.org/wikipedia/commons/e/e5/Gospers_glider_gun.gif
www.mozaicworks.com
Enterprise Agile Architect Role
Contact meUnit testing workshopRemote pair-programmingTDD workshopRefactoring workshopLegacy code workshopLegacy code retreatCode retreat
www.mozaicworks.com
Enterprise Agile Architect Role
Extend your mentoring & training capacityAccelerate learning through communities of practiceGrow your functional leaders and top talents
http://www.mozaicworks.com
@adibolb