Dror Helper Senior consultant Tuesday, July 23, 2013 What’s wrong with TDD
May 11, 2015
Dror HelperSenior consultantTuesday, 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 a unit test?
A method (Code) that
tests specific functionality,
Has clear pass/fail criteria
and runs in isolation
4
This is a unit test!
[TestMethod]public void CheckPassword_ValidUser_ReturnTrue()
{bool result = CheckPassword(“user”, “pass”);
Assert.IsTrue(result);}
5
What about TDD?
RedWrite a failing test
GreenMake the test pass
RefactorClean duplicates and tidy up your code
6
In other words:
Write new Test
Run Test
Write code
Run Tests
Refactor
7
WHY DOESN’T EVERYBODY DOING IT?
If it’s so simple
8
Writing tests takes time which I don’t have
orWriting tests is a waste of time
and besidesTesting is a tester’s job
Reason #1 – it got “Tests” in it
9
But it takes too much time
IBM: Drivers MS: Windows MS: MSN MS: VS0%
20%
40%
60%
80%
100%
120%
140%120%
135%
115%125%
Time taken to code a feature
WithoutTDD Using TDD
10
Is it a waste of time?
IBM: Drivers MS: Windows MS: MSN MS: VS0%
20%
40%
60%
80%
100%
120%
140%
61%
38%24%
9%
Using Test Driven Design
Time To Code Feature Defect density of team
11
Tests costs more timeHowever 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
Can you guarantee there won’t be regression?How do you know that no stupid bugs were created?
Not testing is a decision
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
• Seems more logical• Don’t confuse me with new methodologies• Just as good as tests before
And Finally - no one would ever knowIt’s hard to verify were written using TDD
I’ll write the tests after
15
When you write the tests after the codeYou Miss the point of TDD:
Emergent DesignOnly write the code
you need
TDD is not about the tests
16
Works – but smells
funny
Development Driven Tests
17
Video streamingUI
Closed architecturesLegacy code
If I can’t write tests – how can I use TDD?
Reason # 3 – Not everything is testable
18
You can still test business logic
Use mocking solutions
Remember – TDD is iterative
Not everything is testable - but
19
If you need tochange your code
You have toChange your tests
Reason #4 – TDD locks design
20
IdeallyOnly 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 investmentCounter intuitiveNew skill to learnMight not work for all scenarios
TDD is:
22
a safety net against regressionprevents defects during developmentEnabler of modular, testable codeOnly write the code you needTakes less time than DDT
If done correctly …
TDD is also:
23
There are many excuses not to use TDD
At least try it out before deciding against it.
24
Presenter contact detailsC: 972.05.7668543e: [email protected]: blog.drorhelper.comw: www.codevalue.net