How about "pure virtual methods"?

Jeff Shannon jeff at ccvcorp.com
Tue Dec 21 19:16:23 EST 2004


Noam Raphael wrote:

> But what about the unit tests? They would have still reported a 
> success - where of course they shouldn't have; my classes, in this 
> stage, didn't do what they were expected to do. This problem might 
> arise even when not changing the interface at all - it's quite easy to 
> write a class which, by mistake, doesn't implement all the interface. 
> Its successful unit tests may check every single line of code of that 
> class, but a complete method was simply forgotten, and you wouldn't 
> notice it until you try the class in the larger framework (and, as I 
> understand, the point of unit testing is to test the class on its own, 
> before integrating it).


Except that unit tests should be written to the *specification*, not the 
implementation.  In other words, forgetting a complete method would 
require that you forget to write the method, *and* that you failed to 
translate the specification into unit tests *for that same method*. 

In the context of changing an existing interface, a unit-testing 
scenario would mean that, instead of installing a "pure virtual" method 
on a base class, you'd change the unit-tests to follow the new 
specification, and then write code that would pass the unit tests.  If 
you are subclassing from a common base, then you'd only need to change 
the unit test for that common base class (presuming that all derived 
classes would run those unit tests as well).

Jeff Shannon
Technician/Programmer
Credit International








More information about the Python-list mailing list