http://www.perlmonks.org?node_id=294649


in reply to Inheriting Tests and Other Test Design Issues

I'm not sure that inheritance is the correct thing. In fact, I'm not really sure why you would use inheritance. You're tests should be testing behaviors. So, if two classes have the same behaviors, they should be tested together. For example, if I have a class A and subclass B and they both have a method foo and a->foo() will be equal to b->foo() in all cases, then they should be tested together in the same place.

So, what I would do is something somewhat different from what you have above. For class A and subclass B, I would write:

  • A set of test cases for the common functionality of A and B.
  • A set of test cases for all the unique functionality in A. This might include constructors or methods overridden by B.
  • A set or class of test cases for all the unique functionality in B. This would include all the new functionality in B.

Then, down the road, if I create a new subclass of A, I may have to refactor my test cases to cover all my bases, but it will keep me from repeating code.

  • Comment on Re: Inheriting Tests and Other Test Design Issues