Page 1 of 1
Testing subclasses of a base class
Posted: Sat Aug 27, 2005 10:11 pm
by nielsene
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?
Posted: Sat Aug 27, 2005 10:24 pm
by feyd
I'd definitely verify that the inherited functions are indeed working as expected, just to be safe, although they shouldn't really be affected too much by the child.
Posted: Sun Aug 28, 2005 11:24 am
by McGruff
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.
Posted: Sun Aug 28, 2005 1:18 pm
by josh
Also don't over-look the parent namespace, that is if you want a thorough unit test.