Questions and answers
- What is the connection between testing and clean code?
There is not a direct one, which is why we need to understand how to write clean code. How TDD adds value is that it forces us to think about how our code will be used before we write it and when it is easiest to clean up. It also allows us to refactor our code, changing its structure without changing its function, with certainty that we have not broken that function.
- Can tests replace documentation?
Well-written tests replace some but not all documentation. They become a detailed and up-to-date executable specification for our code. What they cannot replace are documents such as user manuals, operations manuals, or contractual specifications for public application programming interfaces (APIs).
- What are the problems with writing production code before tests?
If we write production code first, then add tests later, we are more likely to face the following problems...