I never waste my time writing tests when the consequences of errors are cheap.
Conversely, I always write tests when the consequences of errors are expensive.
I never waste my time writing tests when the consequences of errors are cheap.
Conversely, I always write tests when the consequences of errors are expensive.
If you are good at testing (like any skill, it requires experience), writing a unit test will be quicker than manually checking the code.
So, perhaps, the cost isn't in writing the tests, but in acquiring the experience to test effectively.
Also, and YMMV, I find writing code in a tests-first manner cuts my stress/frustration of coding by an order of magnitude. It greatly reduces the amount of context I have to keep in my head, so I'm not in the state where I can remember 90% of the information I need to effectively write this class.
In my experience, well factored methods are correct 95% of the time. When there is a bug you notice when you test things that exercise an entire host of methods at once.
> Also, and YMMV, I find writing code in a tests-first manner cuts my stress/frustration of coding by an order of magnitude. It greatly reduces the amount of context I have to keep in my head, so I'm not in the state where I can remember 90% of the information I need to effectively write this class.
Testing is not a good way to help with context. A good debugger and well written code is.
However people who haven't tried methodologies like TDD or BDD shouldn't parrot this as justification for not writing tests. First you need to learn how to write tests, and how to write more testable code. Test-first is invaluable training for developing these skills.
Once you have that experience you are better qualified to decide what constitutes useful testing. Frankly, I find the most value comes from basic sanity tests. Testing obscure edge cases of algorithms is often times not worth it because the mistake is made once and corrected. Having the test case is good (especially if written up front as an excercise in specification), but in many cases the chance that these things will break once fixed approaches 0.
When you are modifying code that customers are already paying you lots of money for errors are expensive.