3 ms·
> "you must cover 90% of your code with unit tests" No, TDD doesn't mean that. TDD is where you write the tests _first_. This bestows numerous advantages that
by abdulhaq 18y ago
> "you must cover 90% of your code with unit tests"
No, TDD doesn't mean that. TDD is where you write the tests _first_. This bestows numerous advantages that post-facto tests don't:
1) You think about the API as required by the person using the interface that you are coding up.
2) - and this is the killer - you are forced to create repeatable test data and fixtures (e.g. in memory sql databases a la sqlite). As the functionality and number of services builds up, you create, whether you like it or not, a large suite of easily instantiated, complex mock services that allow you to build truly automated and repeatable high level tests.
3) And you can then safely refactor much more reliably and confidently when features and ideas have changed.
I agree that writing tests after the fact is a waste of time. TDD saves time (and hair!).
- gaius 18y agoTDD is a brute-force method for evading the need to understand side-effects. I consider situations in which TDD applies to be warning signs, not opportunities.
- deleted 18y ago[deleted]
- eru 18y agoSide-effects are evil [1] and it's good that TDD encourages you to minimize side-effects. [1] That's one reason why functional programming raises productivity.