C++ – how to use cpp unit

c++cppunitunit-testing

Is there a good book or online site discussing the use of the CppUnit, for a beginner?

Best Solution

When you do start to use unit-testing, don't aim for 100% coverage - that way lies madness.

Look to cover all the major methods within the class (the low hanging fruit).

When I started unit testing (via UnitTest++) I went for total coverage, making methods that should of been private protected and then using wrapper classes to be able to test them. Seam functions so I could test classes that were closer to the metal.

A good book on unit testing is Working Effectively with Legacy Code which despite it's name talks about green fields development too, is well written and has good examples to boot.

Update: Also don't worry too much about covering every single possibility at the start when writing the tests. You will miss some stuff. I once had a test that passed but the live code would crash in that function. Running the inputs through the test showed what was wrong and allowed me to rewrite the function so it passed all tests. The original test had held strong for about 7 or 8 months before a customer (unfortunately for me) discovered the bug.