Dror Helper
Senior consultant
Tuesday, July 23, 2013
What’s wrong with TDD
• Software developer & Architect > 10 years
• Senior Consultant
• Agile evangelist
• Blogger – http://blog.drorhelper.com
About.Me
What is a unit test?
A method (Code)
that
tests specific functionality,
Has
clear pass/fail criteria
and
runs in isolation
This is a unit test!
[TestMethod]
public void CheckPassword_ValidUser_ReturnTrue()
{
bool result = CheckPassword(“user”, “pass”);
Assert.IsTrue(result);
}
What about TDD?
Red
Write a failing test
Green
Make the test pass
Refactor
Clean duplicates and tidy up your code
In other words:
Write
new
Test
Run
Test
Write
code
Run
Tests
Refactor
WHY DOESN’T EVERYBODY DOING IT?
If it’s so simple
7
Writing tests takes time which I don’t have
or
Writing tests is a waste of time
and besides
Testing is a tester’s job
Reason #1 – it got “Tests” in it
But it takes too much time
120%
135%
115%
125%
0%
20%
40%
60%
80%
100%
120%
140%
IBM: Drivers MS: Windows MS: MSN MS: VS
Time taken to code a feature
WithoutTDD Using TDD
Is it a waste of time?
61%
38%
24%
9%
0%
20%
40%
60%
80%
100%
120%
140%
IBM: Drivers MS: Windows MS: MSN MS: VS
Using Test Driven Design
Time To Code Feature Defect density of team
Tests costs more time
However
Development takes less Time:
• Less defects
• Rarely need to invoke the debugger
• Every line has a test
• Overcome analysis-paralysis
So do testing waste time?
Hope Driven Development
Can you guarantee there won’t be regression?
How do you know that no stupid bugs were
created?
Not testing is a decision
Writing tests before coding is counterintuitive
How can you know what you’re going to write?
Planning for failure feels wrong
Reason #2 – Tests before code is wierd
• Seems more logical
• Don’t confuse me with new methodologies
• Just as good as tests before
And Finally - no one would ever know
It’s hard to verify were written using TDD
I’ll write the tests after
When you write the tests after the code
You Miss the point of TDD:
Emergent Design
Only write the code you
need
TDD is not about the tests
Development Driven Tests
Video streaming
UI
Closed architectures
Legacy code
If I can’t write tests – how can I use TDD?
Reason # 3 – Not everything is testable
You can still test business logic
Use mocking solutions
Remember – TDD is iterative
Not everything is testable - but
If you need to
change your code
You have to
Change your tests
Reason #4 – TDD locks design
Ideally
Only requirement change (or defect)
would cause tests to break
It means
You have to know how to write robust unit tests
Tests are code too
Requires time investment
Counter intuitive
New skill to learn
Might not work for all scenarios
TDD is:
a safety net against regression
prevents defects during development
Enabler of modular, testable code
Only write the code you need
Takes less time than DDT
If done correctly …
TDD is also:
There are many excuses
not to use TDD
At least try it out before deciding against it.
Presenter contact details
C: 972.05.7668543
e: drorh@codevalue.net
B: blog.drorhelper.com
w: www.codevalue.net

The problem with tdd

  • 1.
    Dror Helper Senior consultant Tuesday,July 23, 2013 What’s wrong with TDD
  • 2.
    • Software developer& Architect > 10 years • Senior Consultant • Agile evangelist • Blogger – http://blog.drorhelper.com About.Me
  • 3.
    What is aunit test? A method (Code) that tests specific functionality, Has clear pass/fail criteria and runs in isolation
  • 4.
    This is aunit test! [TestMethod] public void CheckPassword_ValidUser_ReturnTrue() { bool result = CheckPassword(“user”, “pass”); Assert.IsTrue(result); }
  • 5.
    What about TDD? Red Writea failing test Green Make the test pass Refactor Clean duplicates and tidy up your code
  • 6.
  • 7.
    WHY DOESN’T EVERYBODYDOING IT? If it’s so simple 7
  • 8.
    Writing tests takestime which I don’t have or Writing tests is a waste of time and besides Testing is a tester’s job Reason #1 – it got “Tests” in it
  • 9.
    But it takestoo much time 120% 135% 115% 125% 0% 20% 40% 60% 80% 100% 120% 140% IBM: Drivers MS: Windows MS: MSN MS: VS Time taken to code a feature WithoutTDD Using TDD
  • 10.
    Is it awaste of time? 61% 38% 24% 9% 0% 20% 40% 60% 80% 100% 120% 140% IBM: Drivers MS: Windows MS: MSN MS: VS Using Test Driven Design Time To Code Feature Defect density of team
  • 11.
    Tests costs moretime However Development takes less Time: • Less defects • Rarely need to invoke the debugger • Every line has a test • Overcome analysis-paralysis So do testing waste time?
  • 12.
    Hope Driven Development Canyou guarantee there won’t be regression? How do you know that no stupid bugs were created? Not testing is a decision
  • 13.
    Writing tests beforecoding is counterintuitive How can you know what you’re going to write? Planning for failure feels wrong Reason #2 – Tests before code is wierd
  • 14.
    • Seems morelogical • Don’t confuse me with new methodologies • Just as good as tests before And Finally - no one would ever know It’s hard to verify were written using TDD I’ll write the tests after
  • 15.
    When you writethe tests after the code You Miss the point of TDD: Emergent Design Only write the code you need TDD is not about the tests
  • 16.
  • 17.
    Video streaming UI Closed architectures Legacycode If I can’t write tests – how can I use TDD? Reason # 3 – Not everything is testable
  • 18.
    You can stilltest business logic Use mocking solutions Remember – TDD is iterative Not everything is testable - but
  • 19.
    If you needto change your code You have to Change your tests Reason #4 – TDD locks design
  • 20.
    Ideally Only requirement change(or defect) would cause tests to break It means You have to know how to write robust unit tests Tests are code too
  • 21.
    Requires time investment Counterintuitive New skill to learn Might not work for all scenarios TDD is:
  • 22.
    a safety netagainst regression prevents defects during development Enabler of modular, testable code Only write the code you need Takes less time than DDT If done correctly … TDD is also:
  • 23.
    There are manyexcuses not to use TDD At least try it out before deciding against it.
  • 24.
    Presenter contact details C:972.05.7668543 e: drorh@codevalue.net B: blog.drorhelper.com w: www.codevalue.net

Editor's Notes

  • #10 Taken from http://research.microsoft.com/en-us/projects/esm/nagappan_tdd.pdfRealizing quality improvement through test driven development: results and experiences of four industrial teamsPublished online: 27 February 2008
  • #11 Taken from http://research.microsoft.com/en-us/projects/esm/nagappan_tdd.pdfRealizing quality improvement through test driven development: results and experiences of four industrial teamsPublished online: 27 February 2008
  • #16 Only write the code you needEmergent designDesign during development