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
...
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”, “...
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
Reas...
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
T...
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...
Tests costs more time
However
Development takes less Time:
• Less defects
• Rarely need to invoke the debugger
• Every lin...
Hope Driven Development
Can you guarantee there won’t be regression?
How do you know that no stupid bugs were
created?
Not...
Writing tests before coding is counterintuitive
How can you know what you’re going to write?
Planning for failure feels wr...
• Seems more logical
• Don’t confuse me with new methodologies
• Just as good as tests before
And Finally - no one would e...
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...
Development Driven Tests
Video streaming
UI
Closed architectures
Legacy code
If I can’t write tests – how can I use TDD?
Reason # 3 – Not everythin...
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 ...
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 ...
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
Upcoming SlideShare
Loading in …5
×

The problem with tdd

1,784 views

Published on

Published in: Technology, Education
  • Be the first to comment

  • Be the first to like this

The problem with tdd

  1. 1. Dror Helper Senior consultant Tuesday, July 23, 2013 What’s wrong with TDD
  2. 2. • Software developer & Architect > 10 years • Senior Consultant • Agile evangelist • Blogger – http://blog.drorhelper.com About.Me
  3. 3. What is a unit test? A method (Code) that tests specific functionality, Has clear pass/fail criteria and runs in isolation
  4. 4. This is a unit test! [TestMethod] public void CheckPassword_ValidUser_ReturnTrue() { bool result = CheckPassword(“user”, “pass”); Assert.IsTrue(result); }
  5. 5. What about TDD? Red Write a failing test Green Make the test pass Refactor Clean duplicates and tidy up your code
  6. 6. In other words: Write new Test Run Test Write code Run Tests Refactor
  7. 7. WHY DOESN’T EVERYBODY DOING IT? If it’s so simple 7
  8. 8. 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
  9. 9. 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
  10. 10. 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
  11. 11. 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?
  12. 12. 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
  13. 13. 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
  14. 14. • 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
  15. 15. 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
  16. 16. Development Driven Tests
  17. 17. Video streaming UI Closed architectures Legacy code If I can’t write tests – how can I use TDD? Reason # 3 – Not everything is testable
  18. 18. You can still test business logic Use mocking solutions Remember – TDD is iterative Not everything is testable - but
  19. 19. If you need to change your code You have to Change your tests Reason #4 – TDD locks design
  20. 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. 21. Requires time investment Counter intuitive New skill to learn Might not work for all scenarios TDD is:
  22. 22. 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:
  23. 23. There are many excuses not to use TDD At least try it out before deciding against it.
  24. 24. Presenter contact details C: 972.05.7668543 e: drorh@codevalue.net B: blog.drorhelper.com w: www.codevalue.net

×