R – How much testing is enough?

integration-testing, tdd, unit-testing

I recently spent about 70% of the time coding a feature writing integration tests. At one point, I was thinking “Damn, all this hard work testing it, I know I don’t have bugs here, why do I work so hard on this? Let’s just skim on the tests and finish it already…”

Five minutes later a test fails. Detailed inspection shows it’s an important, unknown bug in a 3rd party library we’re using.

So … where do you draw your line on what to test on what to take on faith? Do you test everything, or the code where you expect most of the bugs?

Best Solution

In my opinion, it's important to be pragmatic when it comes to testing. Prioritize your testing efforts on the things that are most likely to fail, and/or the things that it is most important that do not fail (i.e. take probability and consequence into consideration).

Think, instead of blindly following one metric such as code coverage.

Stop when you are comfortable with the test suite and your code. Go back and add more tests when (if?) things start failing.