in reply to Testing and combinations

How are you setting options? By passing parameters to a new or init method, by calling specific setters on the object, some other fashion?

In any case I'd be inclined to build a table with a list of option and value pairs for each object class. You can then use the table entries to drive generating and configuring object instances as well as validating the result. We really need to see something more of the way the API for your objects is put together though to be able to sketch some practical code.


Perl is environmentally friendly - it saves trees

Replies are listed 'Best First'.
Re^2: Testing and combinations
by talexb (Chancellor) on Oct 30, 2007 at 20:23 UTC

    I'm setting options by adding things to an arg hash, and I am currently using a table to select my two test cases, one without a file, and the other one with. I also have an option that includes specifing a list, and I want to be able to specify a null list, a one element list or a three element list.

    I think I'll use your suggestion of basing it on tables, and pre-populate my tables so that the first entry is 'nothing'; then I just use a serious of next ifs to try all of the different combinations.

    Alex / talexb / Toronto

    "Groklaw is the open-source mentality applied to legal research" ~ Linus Torvalds

      A series of next if ...s sounds like hard work for maintenance if there are more than a few of them. Sketch out your code and post it here if it looks like becoming unwieldy.

      The main thing to consider is that you should be able to handle option lists of arbitrary length without needing to alter the test code. Also you should be able to specify the domain of valid option combinations in the table and have the test code generate the permutations without having to author each case in the test code.


      Perl is environmentally friendly - it saves trees
        my $testNum = 1; for my $thisFile ( undef, 'triple.zip' ) { for my $thisListLength ( qw/0 1 3/ ) { my $testName = "Test-$testNum"; $testNum++; diag "Test $testName with " . (defined($thisFile) ? $thisFile : 'no file') . " and list length $thisListLength"; my $args = { name => $testName }; $args->{'filename'} = $thisFile if (defined($thisFile) ); my $doc = XYZ::SuperDocument->create($args); ok(defined($doc), "$testName object created"); # TODO: Add list stuff as well. _testObject($doc,$args); } }

        Here's what I have so far .. the lists are hard-coded for now, but I will move them to a common location. This is the create loop, and later in another scope I have load, test and delete operations inside an identical loop.

        Alex / talexb / Toronto

        "Groklaw is the open-source mentality applied to legal research" ~ Linus Torvalds