"Frank V. Castellucci" wrote:
>
> I'm a big believer and practitioner of B. Meyers assertion model in
> regards to state invariance. Has the PyUnit team consider a way to
> provide this type testing for Python class and instance? Or is it all
> covered in the existing implementation?
Hi Frank,
Thanks for the question.
I think Unit Testing and Invariance Checking are quite separate things,
and as such, provision of direct support for invariance checking is
outside the scope of PyUnit. Python's built-in 'assert' statement is
there for those who wish to sprinkle it liberally inside their classes,
and Meyer enthusiasts who do so will find that PyUnit recognises as
failures any checked invariants that are violated during a test run.
That's the essence of my reply, but I'll indulge myself by throwing in a
few personal views...
I'm actually a skeptic of the Meyer assertion model, although I am aware
that many other people consider it helpful. My highly personal feeling
is that invariance checking plays an insignificant role in the assurance
that a class works correctly. I would postulate that, for a given class,
there is no invariant whose religious preservation assures that the
class will do what it promises.
Developers want to ensure that their code works properly in all the
conditions in which it has been designed to be used. In my (and the
Extreme Programming) view, unit tests document and test those
'designed-for' conditions, and if the code breaks in any situation not
covered by a unit test, it is being used contrary to the author's plans.
In those breakage cases, invariant assertions could provide helpful
feedback, but I personally would not spend a lot of time writing
assertions that only help if my code is misused. Unit tests *are* the
contract in the XP world view.
Some relevant Wiki wisdom:-
http://c2.com/cgi/wiki?DesignByContractAssertionsVsUnitTestsVsTypes
http://c2.com/cgi/wiki?DoNotUseAssertions
http://c2.com/cgi/wiki?UseAssertions
http://c2.com/cgi/wiki?YouArentGonnaNeedIt
http://c2.com/cgi/wiki?DoTheSimplestThingThatCouldPossiblyWork
It's an area of quite some controversy.
Best wishes,
-Steve
_____________________________________________
Steve Purcell, Technical Director, Inkontact
Get in touch at http://www.inkontact.com/
|