24
Dror Helper Senior consultant Tuesday, July 23, 2013 What’s wrong with TDD

The problem with tdd

Embed Size (px)

Citation preview

Page 1: The problem with tdd

Dror HelperSenior consultantTuesday, July 23, 2013

What’s wrong with TDD

Page 2: The problem with tdd

2

• Software developer & Architect > 10 years

• Senior Consultant• Agile evangelist

• Blogger – http://blog.drorhelper.com

About.Me

Page 3: The problem with tdd

3

What is a unit test?

A method (Code) that

tests specific functionality,

Has clear pass/fail criteria

and runs in isolation

Page 4: The problem with tdd

4

This is a unit test!

[TestMethod]public void CheckPassword_ValidUser_ReturnTrue()

{bool result = CheckPassword(“user”, “pass”);

Assert.IsTrue(result);}

Page 5: The problem with tdd

5

What about TDD?

RedWrite a failing test

GreenMake the test pass

RefactorClean duplicates and tidy up your code

Page 6: The problem with tdd

6

In other words:

Write new Test

Run Test

Write code

Run Tests

Refactor

Page 7: The problem with tdd

7

WHY DOESN’T EVERYBODY DOING IT?

If it’s so simple

Page 8: The problem with tdd

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

Page 9: The problem with tdd

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

Page 10: The problem with 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

Page 11: The problem with tdd

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?

Page 12: The problem with tdd

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

Page 13: The problem with tdd

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

Page 14: The problem with tdd

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

Page 15: The problem with tdd

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

Page 16: The problem with tdd

16

Works – but smells

funny

Development Driven Tests

Page 17: The problem with tdd

17

Video streamingUI

Closed architecturesLegacy code

If I can’t write tests – how can I use TDD?

Reason # 3 – Not everything is testable

Page 18: The problem with tdd

18

You can still test business logic

Use mocking solutions

Remember – TDD is iterative

Not everything is testable - but

Page 19: The problem with tdd

19

If you need tochange your code

You have toChange your tests

Reason #4 – TDD locks design

Page 20: The problem with tdd

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

Page 21: The problem with tdd

21

Requires time investmentCounter intuitiveNew skill to learnMight not work for all scenarios

TDD is:

Page 22: The problem with tdd

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:

Page 23: The problem with tdd

23

There are many excuses not to use TDD

At least try it out before deciding against it.

Page 24: The problem with tdd

24

Presenter contact detailsC: 972.05.7668543e: [email protected]: blog.drorhelper.comw: www.codevalue.net