Slash Boxes
NOTE: use Perl; is on undef hiatus. You can read content, but you can't post it. More info will be forthcoming forthcomingly.

All the Perl that's Practical to Extract and Report

The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.
More | Login | Reply
Loading... please wait.
  • by Ovid (2709) on 2002.12.11 13:12 (#15342) Homepage Journal

    Have you considered using Test::More? It has much more useful testing facilities and it allows you to name tests, which can give you very descriptive testing information. Further, if a test fails, it often provides very useful diagnostic information such as telling you what value you were expecting in $foo and what value $foo actually received. Here's a sample from some tests of a "People" object that I have.

    # testing is_senior_contact()

    $sql = <<"END_SQL";
    SELECT people_id, category_id
    FROM people_category
    WHERE people_id = (SELECT min(people_id) FROM people_category)
    $data = $db->_arrayref( $sql );
    my ( $test_person, $test_category ) = @$data;

    can_ok( $people->[0], 'is_senior_contact' );
    $person = Foo::People->new( $test_person );
    undef $data;
    $data = $person->is_senior_contact( $test_category );
    ok( $data, '... and a senior contact should return true' );
    $data = $person->is_senior_contact( 0 );
    ok( ! $data, '... and return false if they\'re not a senior contact' );

    And this outputs:

    ok 16 - Foo::People->can('is_senior_contact')
    ok 17 - ... and a senior contact should return true
    ok 18 - ... and return false if they're not a senior contact

    If one of those tests fails, I find out instantly what test failed and why. This is a significant improvement over