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

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:

  1. Unit Tests
  2. Integration Tests
  3. Drivers / Interfaces tests
  4. Performance tests
  5. 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

Red-Green-Refactor

TDD Laws

  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.

TDD Mistakes

  1. Write tests after
  2. Fragile tests
  3. Slow tests
  4. Skip refactoring
  5. Skip refactoring tests

TDD Tactics

  1. Triangulation
  2. Write assertion first
  3. Write corner cases first
  4. Given When Then
  5. Mocks external interfaces
  6. Ephemeral Tests

TDD Needs …

  1. Paradigm Shift
  2. Discipline
  3. Creativity
  4. 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

  1. Test-driven Development By Example (Kent Beck)
  2. Modern C++ Programming with Test-Driven Development: Code Better, Sleep Better (Jeff Langr)
  3. Test-driven Development with Python (Harry J.W. Percival)

QUESTIONS?