in reply to Re: starting to write automated tests
in thread starting to write automated tests

well, a use case scenario isn't too difficult. it's a more or less linear path from items in cart to credit card processing.

right now i'm stuck on *why* one of the Test::Simple tests is not returning the "status" message:

#!/usr/bin/perl use strict; use Test::Simple tests => 4; use ShopDB::AuthorizeCard; my $authCard = ShopDB::AuthorizeCard->new(); ok( defined( $authCard ), "new() successful" ); ok( ref $authCard eq 'ShopDB::AuthorizeCard', "blessed into right package" ); ok( defined( $authCard ) and ref $authCard eq 'ShopDB::AuthorizeCard', + "new() successful, blessed into right package" ); ok( $authCard->can( 'AuthorizeCard' ), "found the AuthorizeCard() method" );
gives me:
1..4 ok 1 - new() successful ok 2 - blessed into right package ok 3 ok 4 - found the AuthorizeCard() method
test 3 is just a combination of tests one and two ... but i don't get the ok message back, and i don't get it.

Replies are listed 'Best First'.
Re^3: starting to write automated tests
by petdance (Parson) on Dec 28, 2004 at 22:44 UTC
    First, start with Test::More, not Test::Simple. Use the convenience functions, like so:
    my $authCard = ShopDB::AuthorizeCard->new(); isa_ok( $authCard, 'ShopDB::AuthorizeCard' ); can_ok( $authCard, 'AuthorizeCard' );
    Those convenience methods will save you hassle AND problems like you had. isa_ok() specifically checks definedness for you.

    xoxo,
    Andy

Re^3: starting to write automated tests
by dragonchild (Archbishop) on Dec 28, 2004 at 17:43 UTC
    Try changing the 'and' to a &&. 'and' has a lower precedence than ',' - that's what's causing the problem.

    Being right, does not endow the right to be rude; politeness costs nothing.
    Being unknowing, is not the same as being stupid.
    Expressing a contrary opinion, whether to the individual or the group, is more often a sign of deeper thought than of cantankerous belligerence.
    Do not mistake your goals as the only goals; your opinion as the only opinion; your confidence as correctness. Saying you know better is not the same as explaining you know better.

      guess it's time for a documentation patch!

      from the perldoc:

      EXAMPLE Here's an example of a simple .t file for the fictional Film mo +dule. use Test::Simple tests => 5; use Film; # What you're testing. my $btaste = Film->new({ Title => 'Bad Taste', Director => 'Peter Jackson', Rating => 'R', NumExplodingSheep => 1 }); ok( defined($btaste) and ref $btaste eq 'Film', 'new() works' );
Re^3: starting to write automated tests
by revdiablo (Prior) on Dec 28, 2004 at 18:19 UTC

    Aside from the precedence issue pointed out by dragonchild, I have to wonder why you have test 3 at all? Test 1 and 2 already tested both of those conditions. What's the point of testing them again? Might they have suddenly changed between the tests?

      grr. i hate being in a hurry and forgetting to post, not just preview.

      the first and second tests were there ... so that i could see what was going wrong. it wasn't apparent to me, since this is my first venture into Test::*

Re^3: starting to write automated tests
by rir (Vicar) on Dec 28, 2004 at 20:40 UTC
    use warnings;
    and
    use diagnostics;
    would be your friends, if you let them.

    Be well,
    rir