On Fri, Mar 08, 2002 at 07:14:07PM +0000, Richard Clamp wrote:
> On Fri, Mar 08, 2002 at 06:19:26PM +0000, Simon Wilcox wrote:
> > 
> > So I've written a module, complete with docs and tests.
> > 
> > What's the best way (if there is a way) to figure out if I've tested
> > everything I should test ?
> 
> A good tool to look at is Devel::Cover.  Assuming you're using
> MakeMaker, add this to your Makefile.PL
> 
> sub MY::postamble {
>     return <<EOF
> cover:
> \trm -rf cover_db
> \tPERL5OPT=-MDevel::Cover \$(MAKE) test || true
> \tcover cover_db
> EOF
> }
> 
> and then just C<make cover>.  Your target is 100% statement coverage.

Your results will be in cover_db/cover_db.html.

But be aware that even if you can get 100% statement coverage that
doesn't mean that you've tested everything you should, or that
everything you've tested works, of course.

Statement coverage is the weakest form of code coverage.  Unfortunately,
it's the only one of the test coverage criteria that's properly working
at the moment (if it is properly working, which it probably isn't).  You
could try the condition coverage, but don't place great credence by it
(that's why it's off by default).  Turn it on with:

  cover -condition cover_db

And even if you get 100% code coverage on all the criteria you can think
of, that still doesn't necessarily mean that you've tested everything
that you should.  Unfortunately, there's no substitute for Thinking
Really Hard (tm).

> > How should I structure my tests for maintainability if I'm repeating tests
> > with different values ?

In the past, I have abstracted away the test to its own module, with the
import method taking various options, leaving the test itself as a
simple use statement.

Gedcom.pm on CPAN shows this approach.

> > Why can't my code Just Work [tm] so I don't have to write all these
> > fecking tests ? [1]
> > 
> > Simon.
> > 
> > [1] That's a rhetorical question :-)

Well, if you were to formally prove your program you could dispense with
the testing :-)

-- 
Paul Johnson - [EMAIL PROTECTED]
http://www.pjcj.net

Reply via email to