TDD A Driven Approach To Development Tjakko Kleinhuis 3 December, 2012
Who? Tjakko Kleinhuis Enabler Mechanical engineer Software engineer
Who s still doing agile these days? How s Agile? Agile is so 2006!
It is pulp. Programming, Motherfucker Do you speak it? We are a community of motherfucking programmers who have been humiliated by software development methodologies for years. We are tired of XP, Scrum, Kanban, Waterfall, Software Craftsmanship (aka XP-Lite) and anything else getting in the way of... www.programming-motherfucker.com
It can become fiction. They Claim To Value They Really Value We **cking Do Individuals and interactions Tons of billable hours Programming, Motherf***r Working software Tons of pointless tests Programming, Motherf***r Customer collaboration Bleeding clients dry Programming, Motherf***r Responding to change Instability and plausible deniability Programming, Motherf***r www.promofo.com
We re forgetting.
XP Values / Agile Manifesto Communication Individuals and interactions over processes and tools Simplicity Working software over comprehensive documentation Feedback Customer collaboration over contract negotiation Courage Responding to change over following a plan
Back to the why! Communication Talk to others in their language. Simplicity A (working) product. That s all they want. Feedback Get feedback. Make it concrete. Test & show. Courage Think, but start moving asap to get your feedback, and please, keep moving for your product.
Humanity Economics Mutual Benefit Self-Similarity Improvement Diversity Reflection Flow Opportunity Redundancy Failure Quality Baby Steps Accepted Responsibility XP Principles
Change your way of thinking
Change your way of thinking
TDD under the agile umbrella XP (developers) SCRUM (project management) Continuous Design Test-Driven Development Refactoring Continuous Integration Every change is built and tested Open source tools: CruiseControl
Traditional V-model Requirements Does software match specs? Acceptance Tests Architecture Quality of Design? Integration Tests Design Component Tests Random code tests Code Unit Tests TEST AFTERWARDS
Agile V-model Acceptance Test Communication, Predictability Right Software Feedback Continuous Integration Integration Tests Simplicity & Feedback Unit Tests Lean & Clean code TEST FIRST
Exam metaphore
TDD RHYTHM
Baby Steps
Fail FIRST
Dreams
AND Nightmares
Do s and don ts DO The BIG Why? Stop on pass Shortest route Baby steps Fail first! Dreams AND nightmares DON T Feature creep Over-detail Steam ahead (False!) pass first Dreams only
ISOLATION Seams Fakes (Stubs & Mocks) Interaction vs. state-based testing
Seams
Stubs
Mocks
Isolating an object with dependencies
State-based testing
Interaction-based testing
Show me: mocks
Show me: mocks // setup mock = new Mock (motordevice); button.attachmotor(mock); // some stubbing mock.return(startmotor).value(true); // expectations mock.expect( startmotor ).once(); // trigger button.pressed();
IN THE REAL WORLD New software Size matters Bug fixing Legacy code Test data (Programming) Languages
TDD Pitfall
TDD Pitfall
Granularity
Equal growth
Prioritize?
Sort, don t prioritize 1 2 3
Size matters The right size for a unit test Black box tests too little, often hard Avoid heavy maintenance: overdone white box Open box: test your well-evolved interface!
Traditional Bug Fixing
TDD Bug Fixing
Legacy Code Legacy code = technical debt don't know what it does fear that change will break it
Rhythm for insight
Sprouting
Sprouting
Sprouting
Test data Real data Fixtures
Real data
Fixtures
Fixtures Known data a fixture contains all the things that must be in place in order to run a set of tests and expect a particular outcome Typical setup() and teardown() Repeatable tests
Languages Java (JUnit) C++ (CPPUnit) C# (NUnit) C (CUnit) JMock (a.o.) mockpp, hippo, google Rhino See C++
REFERENCES & CREDITS
Recommended books Working effectively with Legacy Code Michael Feathers TDD by Example Kent Beck
For further reading extreme Programming explained Kent Beck The pragmatic programmer Andrew Hunt & David Thomas Growing OO software, guided by tests Steve Freeman & Nat Pryce
Related subjects Continuous integration Test Automation xunit testing
Credits Dirty Jobs Rob Westgeest a.o. (QWAN) Brain images Dorothy Graham
www.sioux.eu 040-2677100 tjakko.kleinhuis@sioux.eu Sioux 2012 Confidential 57