Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

Re^2: Lessons learned from getting to 100% with Devel::Cover

by davorg (Chancellor)
on Jul 30, 2004 at 08:10 UTC ( [id://378626]=note: print w/replies, xml ) Need Help??


in reply to Re: Lessons learned from getting to 100% with Devel::Cover
in thread Lessons learned from getting to 100% with Devel::Cover

Devel::Cover measures the amount of your code that is exercised by your test plan. If you get 100% coverage then every line of the code being tested is run as part of the test plan.

--
<http://www.dave.org.uk>

"The first rule of Perl club is you do not talk about Perl club."
-- Chip Salzenberg

  • Comment on Re^2: Lessons learned from getting to 100% with Devel::Cover

Replies are listed 'Best First'.
Re^3: Lessons learned from getting to 100% with Devel::Cover
by xdg (Monsignor) on Jul 30, 2004 at 12:41 UTC

    It's more than just every line. Devel::Cover tests every line, every branch (if/else, etc.), and every conditional (A or B or C).

    In my view it's great for reminding one to test edge cases. How often do we write something along the lines of:

    some_function() or die; my $variable ||= 42;

    How many test suites actually test that the die happens, or test the case where the variable doesn't get set in advance? In using Devel::Cover just a little, I've been more thoughtful about where and how I sprinkle defensive logic and I've also made a point of testing to ensure the defenses actually hold in practice.

    -xdg

    postscript: my "test that die happens" comment is poorly phrased, probably a bad example, and justly critiqued below by belg4mit. As adrianh and stvn suggest, the coverage test is really testing the or part and whether some_function is falsifiable, not whether die works. If the code coverage tells us that the die phrase is never executed, it's a reminder that we're making an assumption (that some_function might return false), but not testing that assumption. In practice, the coverage test for some_function itself would probably show that there are untested failure cases that explain why some_function never returns false.

    Code posted by xdg on PerlMonks is public domain. It has no warranties, express or implied. Posted code may not have been tested. Use at your own risk.

      That may just be a stupid example, but testing that die happens?! Why on Bob's less than green Earth would you nay should you do that? Testing your code should not ammount to testing the local perl installation.

      --
      I'm not belgian but I play one on TV.

        That may just be a stupid example, but testing that die happens?! Why on Bob's less than green Earth would you nay should you do that?

        Because testing the case when some_function() returns false is useful. What should happen? Should the program exit? Should the exception be caught? Is a false return value even possible?

        The whole reason I wrote Test::Exception was to make testing this sort of thing easier :-)

        That may just be a stupid example, but testing that die happens?! Why on Bob's less than green Earth would you nay should you do that? Testing your code should not ammount to testing the local perl installation.

        I think you misunderstood. The idea is not to test that die happened, but to test that in certain exceptional circumstances, your code will die. The errors you throw/return/raise and the conditions that lead to that happening, are just as much a part of your code as the rest of it.

        Not testing how your code handles an error, would be like an automaker just assuming the airbags, and crumple free zones work.

        -stvn
Re^3: Lessons learned from getting to 100% with Devel::Cover
by EdwardG (Vicar) on Jul 30, 2004 at 12:59 UTC

    Not to be confused with every path of execution through said code.

     

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others meditating upon the Monastery: (8)
As of 2024-04-19 08:57 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found