An Acute Question on Unit Testing for All Consultants

by Eric

It’s a question from our “client”:

If I’ve got a live project running and gaining profits, I have blackbox testing ensuring all of its functionality, and I’m not going to update the project, do I still need to spend extra cost on adding unit tests for it?

Besides what my colleagues mentioned, my addtional points are as follow:

Unit testing helps to specify the purposes of the different modules within the project, which helps to reduce the cost of re-recognizing the design of the module and thus controls the cost of migrating, reusing and modifying of the modules. What’s more, unit testing makes it easier for future integration of similiar modules, platforms, etc.

According to my past experience, if there are modules to be reused, rarely they are straightforward at first glance. They are either containing complicated logic or they can be rewritten directly without too much effort(we assume people prefer a relectively independent module and thus they are not going to introduce the dependency on the existing resources). In this case it’s hard to migrate the functionality with confidence if there are no reference about the fundamental knowledge of that module.

On the one hand, it’s okay that the comprehensive API is well described in the documentation, but remember, that this is a module within a program instead of a program itself, so the documentation might not be comprehensive enough or it might not be available at all.

On the other hand, not all modules are supposed to be reused 100 percent. Sometimes we need to modify the module according to the new requirements, including changes of inputs, outputs or logics, then API doesn’t help too much, while test cases with sufficient knowledge of the module can lead you to a much easier life. That is, with a fine set of test cases covering all the blind areas of the module, getting to know what scopes the module is trying to cover, you will get a better idea on how to reuse or upgrade that module, thus you will get what you need with less effort and make it less error-prone.

In a word, if you really tend to leverage your existing successful project, a comprehensive “written down” knowledge about it with easy access is a good choice. Then probably you will be interested in adding unit tests for what has been working well so far, as they can be good indicators for the ingredients within the pearl.

Other Open Questions

How do I ensure the correctness of unit tests? How do I judge the quality of unit tests according to the given criteria?