Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical

Re^2: Test/ Code Ratio

by Anonymous Monk
on Jan 28, 2005 at 15:50 UTC ( #426004=note: print w/replies, xml ) Need Help??

in reply to Re: Test/ Code Ratio
in thread 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?
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.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://426004]
[choroba]: The .* at the beginning matches the longest possible substring, so it eats any previous commas
[choroba]: But for CSV, use appropriate modules

How do I use this? | Other CB clients
Other Users?
Others contemplating the Monastery: (6)
As of 2018-05-27 08:56 GMT
Find Nodes?
    Voting Booth?