I am the sole maintainer of a code base of about 2000 lines of code. It's not big, but over time the code became so unmaintainable my boss agreed to give me time to rewrite it from scratch.Since the code became such a nightmare to maintain and extend, I wanted to do things right this time and thought about writing unit tests from day 1 (the current code has no tests). However I'm uncertain about this.On one hand, I estimate the code base will probably never exceed 2000 or 1500 lines of code in size. On the other hand, this app is estimated to be in use for a while, I assume at least for 6 months.So the question is: What size of code base justifies writing unit tests? Is unit testing overkill for a project of this size? Or do the reasons to write unit tests for larger projects apply here as well?Please note that I am aware of the great advantages of having unit test coverage of the code base. I'm simply wondering whether this would be an overkill for such a small app.
Is it an overkill to write unit tests for a small code base?
programming practices;unit testing;testing;language agnostic;maintenance
Is it overkill to write tests for a small code base?Absolutely not.Code bases have a way of growing on us. You've seen this play out first hand already. What was a few hundred LoC grew into a few thousand. A few thousand can easily grow into tens of thousands. Have you ever heard of the broken window theory? If you start with tests, it's more likely that more tests will be written as functionality is expanded and bugs are fixed. If they're not there, people are unlikely to write them later (not to mention that they'll be harder to write later and won't cover as many cases).So, yes, write the tests, but I'd urge you to reconsider completely rewriting the code from scratch. You'd do much better to pick yourself up a copy of Michael Feather's Working Effectively with Legacy Code and putting it under tests before and while you're making changes to it. It's a small project, but that doesn't mean that it can't/won't suffer the same fate as Netscape. 