in reply to starting to write automated tests

The first thing I'd do is define your use cases - what are the standard steps a user should take to do X, Y, or Z. Once you have those, then write system tests for those paths.

Second, I'd look at what objects you have and what their API should be. Then, write unit tests for those objects.

You can use Test::More along with some friends to get both of those items done. For example, WWW::Mechanize can be helpful to write automated system tests.

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.

Replies are listed 'Best First'.
Re^2: starting to write automated tests
by petdance (Parson) on Dec 28, 2004 at 22:47 UTC
    And Test::WWW::Mechanize combines them both, so you can do stuff like
    $mech->get( $homepage ); $mech->content_contains( "Contact us" ); $mech->content_unlike( qr/Under construction/i );

    xoxo,
    Andy

Re^2: starting to write automated tests
by geektron (Curate) on Dec 28, 2004 at 17:36 UTC
    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.
      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

      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' );

      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::*

      use warnings;
      and
      use diagnostics;
      would be your friends, if you let them.

      Be well,
      rir