I have a base class with a fair amount of meta programming to give it the flexibility/abstraction it needs to be rather generic.I do have a lot of subclasses using the common methods in the base class, and I have behavior oriented unit tests covering all of the cases in each subclass.Is it ok to skip testing the base class?
Is it ok to avoid testing base classes?
unit testing;testing
To verify if you have enough tests or not, you can check your code coverage and your branch coverage induced by the tests (maybe by using a coverage tool, maybe manually by reviewing the code paths or by using a debugger). If you come to the conclusion the tests for the subclasses give you a high enough coverage for your base classes code, then adding further tests obviously won't bring you much benefit. On the other hand, if there are code paths you can only test by adding specific tests using the base class directly, then you should go this route.Another possible reason for testing your base class directly is that you want to test a specific function of that class in isolation. Sometimes it can be easier to design test cases directly for a specific method, instead of only testing that method indirectly by calling the methods of your subclasses which use that method.Note that when you have a generic base class for which the typical usage scenario is to derive a subclass, your base class is probably abstract. So for testing such a class you need to make a derivation anyway. For this situation, testing the base class directly could mean to add a special derivation just for testing purposes, of course.