Testing is Overrated
infoq.com
infoq.com
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.
When you are modifying code that customers are already paying you lots of money for 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.
There are some tests that are unassailable -- like checking to see if the output of a sort function is sorted and whether it has pathological complexity. On the other hand, duplicating all the conditionals in the code as tests is bullshit. Mocks are even worse!
But! tests will not increase your quality, they will just keep it.
I watched the video and, indeed, it did not absolve me of my sins.
I find when writing in scripting languages such as ruby against frameworks that are in constant flux, I have little choice but to write tests against key things like user registration, activation, authentication.
I wrote a webapp in erlang 4 years ago. I felt the code "was" the tests since my erlang code was concrete and well guarded. I never had any surprises between test and production.
This is not to bash the value of scripting languages. Its a "pay now or pay later" problem.
So what about Java? Its static typed so I should get the same benefits as I did with erlang right (btw, erlang is not typed)? My experience tells me:
1 - ruby - "pay later"
2 - erlang - "pay now"
3 - java - "pay now and pay later"
I don't know if testing is overrated, because I haven't carefully measured how much hype it gets, but I do know testing is useful.
In it, the author posits the following perspective: a successful test is not one that finds zero errors, a successful test is one that finds errors.
1. Smoke Testing
2. Performance Testing
3. Other tests