The benefits of unit tests are well-known by us, as explained in numerous books and online articles such as this answer in StackOverflow, http://stackoverflow.com/questions/1316101/automated-unit-testing-why-what-which.
However, most authors conveniently forgot to mention a few things about unit tests. Management usually worry about spending too much time on unit tests instead of real software deliverables.
- The size of unit tests is usually larger than the size of related classes being tested. If the size of the class is 100 lines of code, the size of related unit test will be around 200 to 500 lines of code because we have to test different methods and the combination also.
- The size of unit tests will grow exponentially.
- If the size of one class is 500 lines of code, , the size of related unit test will be around 3,000 to 6,000 lines of code.
- If the size of one solution is 1M lines of code such as Microsoft Word, , the size of related unit test will be around 20 to 50M lines of code.
- Programming is an art. Unit tests programming is an art also, which requires almost the same-level software skillsets but in different areas. The same software principles such as SOLID and DRY, etc., apply to unit tests as well.
- Maintenance of unit tests is just like the maintenance of the software, and should be treated as integrated portion of software.
Today I only mention one way to manage problems 1. and 2 is to write smaller classes. The classes will be easier to understand, the unit tests will be easier to write, and the size of unit tests will be smaller as well.