2. Outline
• What is TDD?
• Benefits of TDD
• TDD process
• BDD and TDD
• Installation
• Practice
• Example & docs
1
3. What is Test-driven development (TDD)?
• A part of software development process.
• A programming practice that instructs developers to write new code only if an
automated test has failed.
• Starts with designing and developing tests for every small functionality of an
application.
2
4. Benefits of TDD
• A voids duplication of code
• Make the code clearer, simple and bug free
• Much less debug time
• Code proven to meet requirements
• Confidence to refactor
• Good for teamwork
• Good for developers
• ….
3
5. TDD process
4
• Add a test
• Run all tests and see if the new test
fails
• Write the code
• Run tests
• Refactor code
• Repeat
6. Three laws when applying TDD
1. You are not allowed to write any production code unless it is to make a failing
unit test pass.
2. You are not allowed to write any more of a unit test than is sufficient to fail; and
compilation failures are failures.
3. You are not allowed to write any more production code than is sufficient to pass
the one failing unit test.
5
7. Common errors when applying TDD
• Not interested in failed tests
• Forget the optimal operation after writing code for test pass
• Implement code optimization during coding for test pass => should not do that
• Name cryptic and obscure test
• Do not start with the simplest tests
• Only run each failed test currently
• Write a test with too complicated script
6
8. BDD and TDD
There are two levels of TDD
• Acceptance TDD (ATDD): This test full-fill
the requirement of the specification or
satisfies the behavior of the system.
Called as Behavioral Driven Development
(BDD).
• Developer TDD: Unit test and then just
enough production code to fulfill that
test. The unit test focuses on every small
functionality of the system. Called as
TDD.
7