Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change

comment on

( #3333=superdoc: print w/replies, xml ) Need Help??

We had a strange debate at work today. 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 just want to test what's in the subclass and possibly inherit the tests from the superclass.

The counter-argument, provided by another programmer, is that by failing to explicitly test superclass behavior in the subclass tests, we're losing information. For example, let's say I have a superclass that, amongst other things, formats numbers to have a comma every three digits. My subclasses might change some behavior, but in this example, never change the number format behavior and thus have no tests for it. The problem arises when the super class number formatter is changed to have the comma every four digits, but the subclasses don't have tests for this and thus we're altering subclass behavior without testing it.

Personally, if I have to change a super class, I don't want to find everything that might subclass from it and update all of the tests. I want to run the tests and just fix the ones that break. Copying superclass tests over and over to subclass tests strikes me as a bad idea, but I have to admit that the counter-argument was interesting.

Have you ever used Test::Class or something similar to subclass tests? Do you think it's a good or bad idea? I'm also curious about whether or not you think that good software design considerations are different for tests. Frankly, I see a lot of test code that appears poorly written (cut and paste, mostly), but even bad tests are better than no tests, right?


New address of my CGI Course.

In reply to Inheriting Tests and Other Test Design Issues by Ovid

Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":

  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or or How to display code and escape characters are good places to start.
Log In?

What's my password?
Create A New User
Domain Nodelet?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (1)
As of 2021-07-31 17:34 GMT
Find Nodes?
    Voting Booth?

    No recent polls found