pileofrogs has asked for the wisdom of the Perl Monks concerning the following question:

I'm working on a function with three args. Some inputs are valid, others are not. I want to make Test::More type tests that check all the various combinations of the various valid types and invalid types.

Rather than write several hundred very similar tests by hand, I figure there's got to be a better way.

I've written a sub that takes a description of the test and what it expects, and that's reduced my several hundred hand written tests to several hundred hand-written test descriptions, which is a big improvement, but still error prone.

What I'd really like is a way to describe more generally what the sets of valid and invalid args are and then automatically generate tests. Then I'd know I wasn't forgetting to test any obvious combinations and I'd know my tests really were testing what I wanted.

Are there good practices or tools or modules to help with this kind of thing?

Thanks!
--Pileofrogs

Replies are listed 'Best First'.
Re: Generating Tests
by pc88mxer (Vicar) on May 15, 2008 at 05:03 UTC
    You should take a look at Test::LectroTest which lets you write specification-based tests. It implements a language for specifying domains for test arguments, and will perform probabilistic testing by selecting valid combinations of arguments based on your constraints.