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

Re: Devel::Cover tutorial wanted

by dragonchild (Archbishop)
on Apr 05, 2005 at 12:39 UTC ( [id://444958]=note: print w/replies, xml ) Need Help??


in reply to Devel::Cover tutorial wanted

Devel::Cover tells you how much of your code your tests are exercising. So, if you don't hook it into your tests, how is it supposed to do its job?

Personally, I think your layout is borked. There is no reason to put your t/ directory under lib/Foo/Bar, just because the Foo/Bar levels have no files. Put it as a peer to lib/. So, that way, if you put your t/ there, your cover_db will also be a peer to lib/, which is a good idea. (Also, I'm a little curious why you consider your CGI scripts to be documentation in docs/ as opposed to executables in scripts/ or bin/.)

Now, the numbers being linked are percentages. In other words, what percentage of the branches/conditions/etc. that this "line" has were exercised? But, you can ignore those for now.

Right now, you need to look at the summary page. The important thing here are the boxes which aren't green or white. Those are the ones you need to look at.

  • There's no POD, which may or may not be a bad thing. (I've opened a bug against Devel::Cover because it doesn't allow parameters to Test::Pod::Coverage.)
  • Only 3/4's of the subroutines are being exercised. This is a no-brainer. You should always have a 100% in this category.
  • The branches, conditions, and statements - I would strive for higher.

Now, when you strive for higher in the branches/conditions/statements, that's when you need the linked-to items. You look at those and where it's red, that tells you what you're not testing. For me, I often test my expected cases, but don't always test my failure cases. So, a lot of the code I have to make sure bad things don't happen never gets tested, which shows up in my coverage. I find that if you test all your happy-day scenarios and the basics of your sad-day scenarios, you'll get to 90%+ very quickly.

Replies are listed 'Best First'.
Re^2: Devel::Cover tutorial wanted
by qq (Hermit) on Apr 05, 2005 at 13:00 UTC

    Thanks for your clear response.

    Devel::Cover tells you how much of your code your tests are exercising. So, if you don't hook it into your tests, how is it supposed to do its job?

    Agreed - but as noted, running against the test harness script gives no practical output. I can do it against each .t script individually, but that's a pain. When you run use Devel::Cover, do you run it against a script that calls all your tests, or some other way?

    Personally, I think your layout is borked. There is no reason to put your t/ directory under lib/Foo/Bar, just because the Foo/Bar levels have no files.

    I'll move up the t/ directory. The docs/ is a typo in my node. The real dir is called document_root/, which isn't exactly inspired itself.

    Update: clarified docs/ layout

      Since you are running under mod_perl you need to tell Devel::Cover to look at the code that's being run by apache. Put something like this into your startup.pl. (Or modperl_extra.pl if you are using Apache::Test which I recommend anyway for testing a mod_perl application).
      use Devel::Cover ('+select' => 'My/Module', '+silent');
      Then I would recommend that you look at using something like Module::Build to create your test harness. With it, you can simply run make testcover and it will take care of making sure the test harness has Devel::Cover enabled.
      . . . running against the test harness script gives no practical output.

      How are you doing this? What does your test.pl look like? Is there a reason you're not using prove or 'make test'?

        The best/worst reason: ignorance.

        My test.pl script looks like very like the synopsis from Test::Harness. But, now I've seen it, I'll be using prove from now on.

        The modules are not built with ExtUtils::MakeMaker or Module::Build, so I can't use make test.

        I've a lot to learn yet, so thanks for helping me.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others avoiding work at the Monastery: (6)
As of 2024-04-16 11:15 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found