Testing subclasses of a base class

Discussion of testing theory and practice, including methodologies (such as TDD, BDD, DDD, Agile, XP) and software - anything to do with testing goes here. (Formerly "The Testing Side of Development")

Moderator: General Moderators

Post Reply
User avatar
nielsene
DevNet Resident
Posts: 1834
Joined: Fri Aug 16, 2002 8:57 am
Location: Watertown, MA

Testing subclasses of a base class

Post 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?
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post 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.
McGruff
DevNet Master
Posts: 2893
Joined: Thu Jan 30, 2003 8:26 pm
Location: Glasgow, Scotland

Post 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.
josh
DevNet Master
Posts: 4872
Joined: Wed Feb 11, 2004 3:23 pm
Location: Palm beach, Florida

Post by josh »

Also don't over-look the parent namespace, that is if you want a thorough unit test.
Post Reply