This post originated from an RSS feed registered with Agile Buzz
by James Robertson.
Original Post: Something surprising about SUnit
Feed Title: Richard Demers Blog
Feed URL: http://www.cincomsmalltalk.com/rssBlog/rademers-rss.xml
Feed Description: Richard Demers on Smalltalk
I just learned something surprising about VisualWorks SUnit. If test cases are created in an inheritance hierarchy, lower level test cases inherit "test*" methods from their superclass.
Well yes, that's what inheritance means.
Right, but it never occurred to me that selecting a subclass test case and clicking the RUN button would also RUN the test methods of the superclass test cases.
I am of two minds about this.
On one hand, it is a convenience. Let's assume that test cases are set up in a hierarchy that is parallel to the classes being tested. Then, theoretically, every superclass test needs to be run where an instance of the subclass is the subject of testing; that is, when the subclass test case is run. If only the tests defined by the subclass test case were run, testing would be incomplete, unless tests of the form
testX
super testX
were added to the subclass test case to force running of superclass test methods.
On the other hand, there is nothing saying test cases have to be set up in a parallel hierarchy. In fact, it is a somewhat unnatural thing to do, since test cases are already part of a testing hierarchy. Of course, hierarchies can have multiple purposes, but is that good design? Usually not.
I guess this is a fait accompli that must simply be accepted, but I can't say I liked being surprised. I am probably a bit hard-nosed about such things, but I believe it is a design error to impose a new, unexpected, function on an existing, well-understood mechanism. I really had no reason to think the superclass test methods would be run. There's nothing about it in the VW documentation.
I'd be interested in learning any further rationale for this situation.