Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask

Re: Test/ Code Ratio

by cog (Parson)
on Jan 28, 2005 at 08:32 UTC ( #425878=note: print w/replies, xml ) Need Help??

in reply to Test/ Code Ratio

If you're suspecting you might be testing the same thing several times, why don't you use Devel::Cover to check on that?

Devel::Cover (very easy to use and with exceptional output, including colored HTML) will tell you what's being tested and what's not.

It will not tell you (that I know of) that two tests are doing the same thing, but it might prevent you in the future from duplicating (or triplicating, or whatever) tests.

Replies are listed 'Best First'.
Re^2: Test/ Code Ratio
by Anonymous Monk on Jan 28, 2005 at 15:50 UTC
    If you're suspecting you might be testing the same thing several times, why don't you use Devel::Cover to check on that?
    And how's Devel::Cover going to tell you? All Devel::Cover is going to tell you is whether you have executed certain pieces of code. And how many times. But that won't tell you whether you have tested the same thing twice. Well, unless you think that "running the code once" equals "testing" it.

    Say for instance, you have this function to calculate the cube of a number (pretty stupid function, but the function is not the point):

    sub cube { $_[0] >= 1 ? $_[0] * $_[0] * $_[0] : : - (abs($_[0]) * abs($_[0]) * abs($_[0])) }
    You test it with 2, 1, 0 and -1. Devel::Cover tells you you've executed each branch at least twice. Does that mean you've done twice as much tests as necessary? Not at all, in fact, you haven't done enough tests, as the tests will fail for numbers between 0 and 1.

    Devel::Cover is a great tool, but as with all tools, it becomes pretty useless if you misuse it. Devel::Cover does not tell you what you have tested. Devel::Cover will tell you which statements have run, which branches have been taken, and which subs have been called. From that, you can deduce you haven't tested certain parts of the program, purely because you have run the code. But that's it. It doesn't do more. It cannot be used to decide you have succesfully tested something. It will only show negatives, never positives.

Re^2: Test/ Code Ratio
by moot (Chaplain) on Jan 28, 2005 at 15:29 UTC
    Ah, thanks. Hadn't found that one. Testing the same thing multiple times is indeed one of my concerns, given that I like to test features in isolation.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://425878]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others browsing the Monastery: (5)
As of 2018-03-22 03:01 GMT
Find Nodes?
    Voting Booth?
    When I think of a mole I think of:

    Results (272 votes). Check out past polls.