Improving Design through Test Driven Development (TDD)
Sam Brown @SamuelBrownIVMike McGarr @jmichaelmcgarr
DC Agile Engineering Conference#DCAEC12
About Us
Sam Brown• 11 years software engineer• DevOps Evangelist at Excella• Certified Scrum Master• Puppet Certified
Professional
Mike McGarr• 11 years software engineer• Directory of DevOps for
Blackboard Learn• Founder of the DC
Continuous Integration, Delivery and Deployment Meetup
Types of Tests
Unit Tests
Fast
Independent
Repeatable
Self-Verifying
Timely
Test Driven Development
http://reddevnews.com/articles/2007/11/01/testdriven-development-tdd.aspx
Golden Rule of TDD:Never write production code without a failing test
TDD improves quality
http://www.manning.com/koskela2/
anddesign
Coupling
Cohesion
Object Oriented Design Principles
Single responsibility principle (SRP)
Open/close principle (OCP)
Liskov substitution principle (LSP)
Interface segregation principle (ISP)
Dependency inversion principle (DSP)
Bowling Game• Ten Frames per game• 2 rolls per frame• Unless a strike is rolled
• Properly calculate Spares• Properly calculate Strikes
http://playcasper.com/venues/show/17
Design Decision
Design Decision
Notice the duplication in the tests. Let’s
refactor this.
More duplication
Design Problem – roll() calculates score
Let’s Refactor!
We need a concept of frames.
Ugly Code
Design Decisions
• Design client interface
• Refactor• Change design without changing behavior
• Defer to last responsible moment• Avoids “Big Upfront Design”
New Requirements!
Requested Changes
The Bowling game is becoming service oriented!
• New Requirement:– Post rolls in real-time
Collaborator
Test Doubles
• Dummy• Stubs• Fake• Mocks• Spy
NullPointerException!We need a default implementation.
Contact Us
• J. Michael McGarr• [email protected]• @jmichaelmcgarr• http://earlyandoften.wordpress.com• DC CI Meetup - http://bit.ly/YRnrwx
Sam [email protected]@SamuelBrownIVhttps://github.com/samueltbrown
Cute Baby Arrival 12/20/2012
Top Related