Test-Driven Development
... and Test-Driven Design
Write the tests before you write the code
- Keeps you focused on the program requirements
- Ensures that the code is written to be testable
- Encourages the writing of manageable, modular code
- Encourages the design of fixed APIs
Test Driven Development
[Wikipedia]
Test Driven Design
Design your API
- What will the subroutine be called?
- What arguments will the subroutine take?
- How will those arguments be encoded?
- What will the subroutine output and return?
- What are your test cases?
Test Cases
What do we test?
- Normal, expected data
- Edge cases
- Data that should fail
- Data that should give errors (and fail cleanly!)
Overlapping Rectangles - Edge cases
- Correct behaviour for an edge case depends on the application
- side-to-side
- corner-to-corner
Debugging
A variation of the test cycle