Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

Re: Testaholics Anonymous (or how I learned to stop worrying and love Test::More)

by xdg (Monsignor)
on Mar 31, 2004 at 17:44 UTC ( [id://341354]=note: print w/replies, xml ) Need Help??


in reply to Testaholics Anonymous (or how I learned to stop worrying and love Test::More)

After reading an article on it in TPJ and trying it out, I strongly recommend checking out Devel::Cover. It automates the process of seeing how much of your code is actually tested by your test suite and produces a fantastic HTML drill-down report. It will track the execution of statements, branches, conditions, subroutines, and pod.

Perhaps one day this will even lead to test-driven test development for those of us who are too lazy to do test-driven development itself -- i.e. what's the minimal amount of test suite I need to write to actually exercise the code I've already written?

-xdg

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.

  • Comment on Re: Testaholics Anonymous (or how I learned to stop worrying and love Test::More)

Replies are listed 'Best First'.
Re: Re: Testaholics Anonymous (or how I learned to stop worrying and love Test::More)
by Ovid (Cardinal) on Mar 31, 2004 at 17:50 UTC

    Excellent suggestion. The question of "what do I test?" should always be answered with "what have you tested"? and Devel::Cover does a great job of that. I've wowed coworkers with its HTML output :)

    <malden type="karl">Devel::Cover. Don't leave home without it.</malden> (have I just dated myself?)

    Cheers,
    Ovid

    New address of my CGI Course.

      Ovid

      I am actually running some of my tests through Devel::Cover right now, and and something just popped up.

      What about on coverage for things like this:

      return wantarray ? @results : \@results;
      Devel::Cover reports that I have only tested the @results return value branch. Should I test the \@results branch too, or is this being too granular?

      -stvn

        You know, one thing that I forgot to mention, but it's vitally important to remember: if you find out you didn't test something, you might want to ask yourself if you have dead code. In your example, do you ever call that code in scalar context? (well, void context would also exercise that condition, but we'll ignore that) If not, you have dead code. If you do call it in scalar context, why are you overloading the return value? If you don't need to, perhaps this is an opportunity to simplify your code and thereby reduce the chances of bugs.

        Cheers,
        Ovid

        New address of my CGI Course.

        Personally, I think something like that is too trivial to test -- until it breaks. If that's the only thing that Devel::Cover says you've missed, go ahead and toss the test in there if you like. Otherwise, concentrate on the "big ticket items" and only test that if it breaks (or if you feel like it. Some people are happy to test everything).

        Cheers,
        Ovid

        New address of my CGI Course.

Re: Re: Testaholics Anonymous (or how I learned to stop worrying and love Test::More)
by stvn (Monsignor) on Mar 31, 2004 at 20:56 UTC

    Yes, Devel::Cover is one of my favorite new toys too. I just actually showed it to my boss to demonstrate exactly what you are saying, how we can test test-coverage. He was really impressed, it was one more thing to help me in selling this way of testing.

    Do you happen to have a link to that TPJ article? I actually read about this module on CPAN (saw it in the CPAN nodelet one day and was intrigued), but i would love to read the article.

    -stvn

      Unfortunately, TPJ is subscription-only now and doesn't seem to put archives online anymore since they went to a subscription model. (Even for subscribers! I can only find a link to the previous month, not historical months.)

      -xdg

      P.S. (Added 4/1 and not a joke): For those looking for more info, Paul Johnson, the author of Devel::Cover, has an paper and slideshow from YAPC::Europe::2002. There's also a very interesting look at coverage on various CPAN modules.

      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.

        xdg

        Thanks for the update this looks to be a wealth of info on this. I was actually going to spend part of my day googling code coverage, but this is even better. If i could ++ more I would!

        -stvn

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others rifling through the Monastery: (9)
As of 2024-04-18 13:07 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found