Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

Re: Inheriting Tests and Other Test Design Issues

by dws (Chancellor)
on Sep 27, 2003 at 23:06 UTC ( [id://294690]=note: print w/replies, xml ) Need Help??


in reply to Inheriting Tests and Other Test Design Issues

Basically, the question was whether or not it was appropriate to inherit tests. I argued that it was. If I write a subclass, I don't want to rewrite all of the tests.

I look at it this way: I write objects because I want them to behave in particular ways. If I can save code by factoring common stuff out into superclasses, great, but at one conceptual level, that's just an organizational optimization. If I can get some behavior for free by subclassing an existing class, great. But again, that's an optimization (saving the time and effort it would take me to redo the equivalent work). What I still have is objects with behavior, and I want unit tests that cover that behavior. That means complete coverage of every class. Now, if it just so happens that there's some common testing that can be factored into a unit test superclass, great. But again, that's just an organizational optimization.

I might end up with an inheritance hierarchy in my tests that doesn't match the inheritance hierarchy in my domain objects. Though I've factored domain behavior into abstract superclasses, I don't intentionally set out to write unit tests for those superclass. I might get the same effect by factoring unit tests, but I might not. But in all cases (in theory, at least :), my non-abstract classes have unit tests that cover the behavior I'm interested in.

That's a slightly different way of looking at the world than the two options in your question allow, but it works well for me.

  • Comment on Re: Inheriting Tests and Other Test Design Issues

Replies are listed 'Best First'.
Re: Re: Inheriting Tests and Other Test Design Issues
by dragonchild (Archbishop) on Sep 29, 2003 at 13:10 UTC
    I agree. If behaviors A, B, and C are provided by the superclass, then A, B, and C should be tested in the super-test. My subclass provides behavior D, thus I provide tests for behavior D, inheriting the tests for behaviors A, B, and C. If the superclass changes its behavior, it will change its tests. My testing of my subclass will inherit the changes in the tests. No problem.

    ------
    We are the carpenters and bricklayers of the Information Age.

    The idea is a little like C++ templates, except not quite so brain-meltingly complicated. -- TheDamian, Exegesis 6

    Please remember that I'm crufty and crochety. All opinions are purely mine and all code is untested, unless otherwise specified.

      I agree. If behaviors A, B, and C are provided by the superclass, then A, B, and C should be tested in the super-test.

      That's not what I recommended. Please re-read what you think you're agreeing with.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://294690]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others romping around the Monastery: (3)
As of 2024-04-25 23:50 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found