Messy unit tests, rewrite or keep them and add substitutes?

Started by
0 comments, last by RobTheBloke 11 years, 7 months ago
I have a C++ library, and I will develop and maintain it for quite long time (at least several years).
So robust unit tests are very important to back up the library quality.

Now there are more than 600 unit test cases, 21000 LOC. Note some test cases are really large, not small cases.
Currently the unit tests are a little messy, because I wrote most them when I didn't have much experience on unit testing (still not for now :( ).

Two biggest problems are,
1, The unit tests don't cover all or most code. That's not because of there are not enough unit test, but the unit test structure is a little wrong.
2, I'm a lazy developer and always want to find easy way to do my work. So a lot of unit tests are coupled together via common code, which is not fine for unit test, IMHO.

My question is, should I rewrite the whole unit tests, or keep current unit tests there and add a complete new unit test system?
I don't think current unit test code base can be reused in new unit tests because the current unit test structure/organization is not very good. I need to restructure them.

https://www.kbasm.com -- My personal website

https://github.com/wqking/eventpp  eventpp -- C++ library for event dispatcher and callback list

https://github.com/cpgf/cpgf  cpgf library -- free C++ open source library for reflection, serialization, script binding, callbacks, and meta data for OpenGL Box2D, SFML and Irrlicht.

Advertisement

My question is, should I rewrite the whole unit tests, or keep current unit tests there and add a complete new unit test system?

Life is too short to spend time rewriting unit tests. Enjoy time writing new fun exciting bits of code instead.


I don't think current unit test code base can be reused in new unit tests because the current unit test structure/organization is not very good. I need to restructure them.
[/quote]
Then keep the tests you have, and enhance them with new tests for the new aspects of the code you write. Unit tests can exist in more than one executable. The only real time it's worth doing any serious refactoring work on tests, is if you need to change the framework for better test reporting. So if you are convinced that rewriting your unit tests is a good idea, I'd recommend that you first set up a CI/build server (somethink like jenkins for example). AT least you'd know then, that the refactoring work you do, will probably be the last time you ever need to do that (well, probably not the last, but should be good for 5 years or more).

So a lot of unit tests are coupled together via common code, which is not fine for unit test, IMHO.[/quote]
If the common code is reliable (i.e. tests exist for it), then there is nothing wrong with that approach.

The unit tests don't cover all or most code. That's not because of there are not enough unit test, but the unit test structure is a little wrong.[/quote]
Code coverage tools will help you identify any untested code paths, although generally, the law of diminishing returns applies once you get past 80% coverage or so.

This topic is closed to new replies.

Advertisement