HelloWorld_Always
HelloWorld_Always

Reputation: 1565

Unit testing of the Base Class a good approach

I am unit testing some software in C++ which has base and derived classes. I was wondering if it is actually a good approach to test both the base as well as the derived classes or should one proceed to unit test only derived classes and leave the base class alone ?

Upvotes: 2

Views: 259

Answers (1)

Tom Kerr
Tom Kerr

Reputation: 10720

It is generally best to test anything with an implementation.

Consider breaking any implementation in the base up into smaller, dumb concrete objects and reusing them by composition. Those are easier to unit test than some weird object hierarchy.

Then each derived object only needs to test that it is still valid, given the shared implementation is correct.

Upvotes: 1

Related Questions