http://qs321.pair.com?node_id=341452


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

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
  • Comment on Re: Re: Re: Testaholics Anonymous (or how I learned to stop worrying and love Test::More)
  • Select or Download Code

Replies are listed 'Best First'.
Re(4): More tests or dead code?
by Ovid (Cardinal) on Apr 01, 2004 at 01:52 UTC

    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.

Re: Re: Re: Re: Testaholics Anonymous (or how I learned to stop worrying and love Test::More)
by Ovid (Cardinal) on Apr 01, 2004 at 00:40 UTC

    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.