When you're testing a subclass, do you retest the inherited functionality?
I've done the tests for the new/overrided behavoir. But I haven't tested the inherited behavvoir. I'm about to add an assertIsA with the base class name. Is that sufficient for testing? or should I also assert that the other functions behave as they did in the base class, if I'm relying on that?
Testing subclasses of a base class
Moderator: General Moderators
I'm not sure really - I'd decide based on the specific class.
If the derived class merely adds something new to the base class without really interacting with it, I wouldn't bother. However, it's likely to be more complicated than that. If you partially mock, you can knock out inherited methods and check expectations like call counts etc. This is treating the parent and child like two separate classes with the test checking that the child calls the (private) parent methods correctly.
Or it might be simpler to create a shared test case containing tests for any public methods in the base class, and then extend with a test case for each derived class, adding on some more tests specific to the childs.
If the derived class merely adds something new to the base class without really interacting with it, I wouldn't bother. However, it's likely to be more complicated than that. If you partially mock, you can knock out inherited methods and check expectations like call counts etc. This is treating the parent and child like two separate classes with the test checking that the child calls the (private) parent methods correctly.
Or it might be simpler to create a shared test case containing tests for any public methods in the base class, and then extend with a test case for each derived class, adding on some more tests specific to the childs.