Question

I wonder if there is such a thing as a code line count for a project after which it's preferable to start introducing unit tests, so the things don't get out of control. I think that for some small projects (5-10k lines of code for example) you won't need unit testing, but for large ones of course it's a good idea. Our project is about 100k lines of code, and we already have fears when it comes to making some changes.

So how do I know when to start introducing unit tests in the project ?

Was it helpful?

Solution

As always, whether or not to unit test depends on your motivation for testing.

  • Is the software mission-critical?
  • What is the cost of a failure?
  • How easily can you address errors, if they occur?

The higher the cost of failure, the more important it is to test your software. Here I'm reminded of Steve Freeman's excellent article on Safe Fail versus Fail-Safe. At one end of the spectrum, you can just let your software fail, and fix the errors as they pop up in the wild; at the other end of the spectrum, an error could be disastrous (loss of life).

Thus, it's impossible to answer the question as posed, but I second Simon's comment above that if you do Test-Driven Development (which comes with a lot of other benefits), the line count at which you start unit testing is 0.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top