Content
 What is TTD?
Unit Test & Refactoring
Got Bugs?
Tenets of TTD.
Benifits of TDD.
Advantages & Disadvantages of TDD.
What is TDD?
 It is just about writing the test before the program.
It’s a testing technique as well as a design Technique.
In the end, there is no code without a test.
The developer can tell at any time.
Unit Tests and Refactoring are the tools of TDD.
Unit Tests
 Easy to read & understand.
Execute very quickly.
Independent of execution order.
Test specific aspects of a functionality.
Tests a very small section of code isolation.
Rapid feedback.
Refactoring
 Take existing code & change it more efficient.
Change the internal structure of code without changing
its external behavior.
Ex :-
•ab + ac = a(b+c)
Same result, but the expression is simplified.
Start Write a test for
new capability
Compile
Fix compile
errors
Run the testRun the test
And see it failAnd see it fail
Write the code
Run the testRun the test
And see it passAnd see it pass
RefactorRefactor as neededas needed
Red/Green/Refactor
Got bugs?
 Go after defect.
 Writing a test to expose it..
Write code needed to fix it.
Refactor.
Repeat.
Measure the result.
Tenets of TDD
 Split work into small requirements.
 Always start by writing a test.
Eliminate duplication.
Write the simple code to pass the test.
What can test by TDD?
 Valid inputs.
 Invalid inputs.
Errors, exceptions and events.
Boundary conditions.
Benefits for Developers
 Much less debug time.
 Code proven to meet requirement.
Test become Safety Net.
Process consulting.
Project mentoring.
Eliminate bugs.
Benefits for Business
 Shorter development cycles.
 Near zero defect.
Test become an asset.
Test are documentation.
Competitive advantage.
 Gets running code very quickly.
Development in small steps. This will make debugging
easier since we will have small code chunks to debug.
Produce fully testable code.
Design to the specification, don’t over engineer.
Advantages
 “Write test, write code to pass test, repeat” loop is
overly strict.
Setup requires some what complex wiring.
Causes people to take paths they wouldn’t otherwise.
Disadvantages
References
 “Test-Driven Development By Example”; Kent
Beck;2003.
“Refactoring, Improving The Design Of Existing Code”;
Martin Fowler;1999.
“Patterns Of Enterprise Application Architecture”; Martin
Fowler;2003.
Test Driven Development

Test Driven Development

  • 2.
    Content  What isTTD? Unit Test & Refactoring Got Bugs? Tenets of TTD. Benifits of TDD. Advantages & Disadvantages of TDD.
  • 3.
    What is TDD? It is just about writing the test before the program. It’s a testing technique as well as a design Technique. In the end, there is no code without a test. The developer can tell at any time. Unit Tests and Refactoring are the tools of TDD.
  • 4.
    Unit Tests  Easyto read & understand. Execute very quickly. Independent of execution order. Test specific aspects of a functionality. Tests a very small section of code isolation. Rapid feedback.
  • 5.
    Refactoring  Take existingcode & change it more efficient. Change the internal structure of code without changing its external behavior. Ex :- •ab + ac = a(b+c) Same result, but the expression is simplified.
  • 6.
    Start Write atest for new capability Compile Fix compile errors Run the testRun the test And see it failAnd see it fail Write the code Run the testRun the test And see it passAnd see it pass RefactorRefactor as neededas needed Red/Green/Refactor
  • 7.
    Got bugs?  Goafter defect.  Writing a test to expose it.. Write code needed to fix it. Refactor. Repeat. Measure the result.
  • 8.
    Tenets of TDD Split work into small requirements.  Always start by writing a test. Eliminate duplication. Write the simple code to pass the test.
  • 9.
    What can testby TDD?  Valid inputs.  Invalid inputs. Errors, exceptions and events. Boundary conditions.
  • 10.
    Benefits for Developers Much less debug time.  Code proven to meet requirement. Test become Safety Net. Process consulting. Project mentoring. Eliminate bugs.
  • 11.
    Benefits for Business Shorter development cycles.  Near zero defect. Test become an asset. Test are documentation. Competitive advantage.
  • 12.
     Gets runningcode very quickly. Development in small steps. This will make debugging easier since we will have small code chunks to debug. Produce fully testable code. Design to the specification, don’t over engineer. Advantages
  • 13.
     “Write test,write code to pass test, repeat” loop is overly strict. Setup requires some what complex wiring. Causes people to take paths they wouldn’t otherwise. Disadvantages
  • 14.
    References  “Test-Driven DevelopmentBy Example”; Kent Beck;2003. “Refactoring, Improving The Design Of Existing Code”; Martin Fowler;1999. “Patterns Of Enterprise Application Architecture”; Martin Fowler;2003.

Editor's Notes

  • #7 Unit test levels Red 􀂄 Write a little test that doesn‘t work (and perhaps doesn‘t even compile at first). Green 􀂄 Make the test work quickly (committing whatever sins necessary) Refactor 􀂄 Eliminate all of the duplication created in merely getting the test to work, improve the design.
  • #13 TDD makes you produce 100% testable code You won’t spend a long time with non-running code Your code will always meet the design specifications