TEST DRIVEN DEVELOPMENT
DPUG - 09/08/2009 - Jason Ragsdale
What is TDD?
Test-driven development (TDD) is a software development technique
that relies on the repetition of a very short development cycle:
1. First write a failing automated test case that defines a desired
improvement or new function
2. Then produce code to pass that test
3. Finally refactor the new code to acceptable standards.
The Three Laws of TDD
1. Don’t write any code unless it is to make a failing test pass.
2. Don’t write any more of a unit test than is sufficient to fail.
3. Don’t write more code than is sufficient to pass the one failing unit test.
The first goal is to make the test pass.
Subsequent users have a greater level of trust in the code.
Some Code is Hard to Test.
Don’t Test That Code, Minimize that Code.
Put the important code in a library and test that code.
Management support is essential.
Without the organization support, that TDD is going to improve the
Management will feel that time spent writing tests is wasted.
Badly written tests, are expensive to maintain.
The level of coverage and testing detail achieved during repeated TDD
cycles cannot easily be re-created at a later date.
Therefore these original tests become increasingly precious as time goes
If a poor architecture, a poor design or a poor testing strategy leads to a
late change that makes dozens of existing tests fail, it is important that
they are individually fixed.
Merely deleting, disabling or rashly altering them can lead to un-
detectable holes in the test coverage.
Unexpected gaps in test coverage may exist or occur for a number of
One or more developers in a team was not so committed to the TDD
strategy and did not write tests properly.
Some sets of tests have been invalidated, deleted or disabled
accidentally or on purpose during later work.
Alterations may be made that result in no test failures when in fact bugs
are being introduced and remaining undetected.
Unit tests created in a TDD environment are typically created by the
developer who will also write the code that is being tested.
The tests may therefore share the same blind spots with the code.
The high number of passing unit tests may bring a false sense of security
A unit is the smallest testable part of an application.
Individual software modules are combined and tested as a group.
It occurs after unit testing and before system testing.
Testing conducted on a complete, integrated system to evaluate the
system’s compliance with its specified requirements.
Falls within the scope of black box testing, and as such, should require no
knowledge of the inner design of the code or logic.
Ok Now What?
No enhancements without defined requirements.
Can not write tests for items without requirements.
Three Rules of TDD
TDD - Wikipedia
BDD - Wikipedia