TDD: What, How, and Why
How TDD can save you time, resources and nerves while developing, and how to introduce it in your project.
Hey! ๐
I'm Alex, developer at DRIVE2.RU
I write a technical blog and online books about development. Today I want to discuss TDD and why I use it in my work.
One of the projects where I use TDD.
Chapter 1
Culture and Tests
Project without Tests
Advantages of Testing
- ๐ No regressions
- ๐ Supplement to the documentation
- โ๏ธ Up-to-date code description
NO ๐ฅ TIME! ๐ฅ MERGE ๐ฅ TO PROD! TESTS ๐ฅ LATER, ๐ฅ AAAH!
TDD Helps Solving These Problems
Advantages of TDD
- ๐ No โextra workโ problem
- ๐ Writing tests and refactoring becomes a habit
- ๐ท Refactoring is safer
- ๐ Entities that โdo too muchโ are more noticeable
- ๐ฆ API is designed before implementation
Costs
- ๐ง Need to โturn brains inside outโ
- ๐ฆ โEncourages to think only about the Happy Pathโ
- โณ Need to plan ahead from the beginning
How to Simplify Testing
- ๐งผ Use pure functions more often
- ๐ช Pay attention to coupling
- ๐ฅท Test only your own code
- ๐ Use handy tools
- ๐ธ Spend time on a convenient infrastructure
How to Find Smelly Code
- ๐ณ Too many tests
- ๐คท Description refers to unrelated things
- ๐ฎ Expectations are unclear
- ๐ง Test preparation is too complex
- โ๏ธ Test checks the details of the implementation
- ๐ Library needs a mock
- โ Test is always green
How to Help Team Lead See the Benefit
- ๐ Most likely, they realize they need it
- ๐ Measure bass factor, regressions, documentability
- ๐ Measure the same parameters with tests, compare
- ๐ซ Be a partisan (if things are really bad)
How to Help Biasness See the Benefit
This will work if the project is not a prototype.
- ๐งโ๐ฌ Cite research about testing
- ๐ฌ Measure regressions, time to support and implement features
- ๐งฌ Compare longevity of projects with and without tests
- ๐งโ๐ป Compare average employee time on projects with and without tests