views:

59

answers:

1

I have a series of PHPUnit tests to validate a class, "Class A".
I have another class, "Class B" which extends Class A.

Is there a good way to test that "Class B passes Class A's tests", or in other words "Class B behaves like Class A" without duplicating the test code?

I could test for the extends (using instanceof), but that seems like a misleading test.
I care that it behaves like Class A, not that it extends Class A, right? or wrong?

+1  A: 

Just extend the PHPUnit test case of class A, for class B, that should do it.

Saem
Agreed. Also, of A and B simply implement the same interface, you could have a base test case C that test cases A and B extend.
Michael Johnson