When you use composition, you can mock other objects that your test class depends on, but when you use inheritance, you cannot mock the base class. (Or you can?)
Usually I try to prefer composition over inheritance , but sometimes inheritance really seems to be the best tool to work with - well, at least until it happens for unit testing.
So how do you check inheritance? Or are you just destroying it as an unverifiable and used composition?
Note: I mainly use PHP and PHPUnit, so help on this side is most appreciated. But it would be interesting to know if there are solutions to this problem in other languages.
Use a unit test suite that reflects a class hierarchy. If you have a base class Base and a derived class Derived, then there are test classes BaseTests and derivatives of this DerivedTests. BaseTests is responsible for testing everything that is defined in Base. DerivedTests inherits these tests and is also responsible for testing everything in Derived.
Base ( ), , .
, , . Unit test .
, , - , , (, , , , ..). , . , , . , !
, . , , , , - , , . , .
, ( ) , .
?
, .
, ( - ), , .
, . , overriden , . NO WAY . , , .