TDD for Dummies
How to Pretend to be a Great Programmer
and Get Away With It
I’m not a great programmer. I’m just a good programmer with great habits
– Kent Beck
Why TDD?
TDD enables us to write software with much higher quality faster
Testing Pyramid
How to Read Testing Pyramid
- Lower pyramid is cheap
- Lower pyramid is fast
- Lower pyramid is reliable
Lower pyramid should be as many as possible
What to tests?
Everything that can break:
- Unit Tests
- Integration Tests
- Drivers / Interfaces tests
- Performance tests
- UI tests
What is TDD?
- TDD is not about testing (Surprise!)
- TDD is double entry book keeping
- TDD is test-first
TDD is growing software by writing tests
TDD Sacred Cycle
TDD Laws
- You are not allowed to write any production code unless it is to make a failing unit test pass.
- You are not allowed to write any more of a unit test than is sufficient to fail; and compilation failures are failures.
- You are not allowed to write any more production code than is sufficient to pass the one failing unit test.
TDD Mistakes
- Write tests after
- Fragile tests
- Slow tests
- Skip refactoring
- Skip refactoring tests
TDD Tactics
- Triangulation
- Write assertion first
- Write corner cases first
- Given When Then
- Mocks external interfaces
- Ephemeral Tests
TDD Needs …
- Paradigm Shift
- Discipline
- Creativity
- Management support
DEMO
Given a string of RPN expression, calculate the result
- Valid input characters: 1 2 3 4 5 6 7 8 9 0 + - * /
References
- Test-driven Development By Example (Kent Beck)
- Modern C++ Programming with Test-Driven Development: Code Better, Sleep Better (Jeff Langr)
- Test-driven Development with Python (Harry J.W. Percival)