Testing is all about checking for the stuff that shouldn't go wrong, but might, as well as defining what your code should do, and verifying it. It's all about writing down the bones of what the code is supposed to do, and then making sure you didn't break it somewhere along the line, and in the case of module distros, that it works on platforms other than yours.

Here's a crash course in the whys: http://petdance.com/perl/automated-testing/ I'll also be giving a session on automated testing at OSCON 2003, which will be more example-heavy and less about philosophy.

Here's another: any core module in the Perl distro, or any particularly well-tested module on the CPAN.

Accumulate your tests over time. Let 'em build up like so many soldiers against bugs. Quantity is almost as important as quality.

Test the edges. How is your module supposed to handle an invalid parm to the constructor? Define it, document it, then test that that happens. How about specifying a buffer size of 0? etc etc.

Basically, if the docs say your module is supposed to do something, then the tests should test exactly that.

Remember that there are no stupid tests. The following

        $foo->set_bar( 12 );
        is( $foo->get_bar, 12, "Accessor works" );

is perfectly valid as a test, and should be done for every accessor you have. "But it's an accessor! How can that fail?" I don't know, but when it does, you want to know why.

I'd be glad to take a look at your module. It's a lot easier to poke at specifics.

xox,
Andy

--
Andy Lester
[EMAIL PROTECTED], AIM:petdance
http://petdance.com/ http://use.perl.org/~petdance/



Reply via email to