Perl Test Class

last modified: December 4, 2005

Test::Class (http://search.cpan.org/dist/Test-Class) is a PerlLanguage xUnit TestingFramework. Unlike PerlUnit Test::Class is built on top of Perl's standard PerlTap based testing framework.

An example test class:

{ package MoneyTest;
  use base 'Test::Class';
  use Test::More;

  my ( $chf_12, $chf_14, $usd_28 );

  sub make_fixtures : Test( setup ) {
      $chf_12 = Money->new( CHF => 12 );
      $chf_14 = Money->new( CHF => 14 );
      $usd_28 = Money->new( USD => 28 );
  },

  sub simple_add : Test {
    is_deeply( $chf_12+$chf_14, Money->new( CHF => 26 ) );
  },

  sub money_bag : Test {
    is_deeply( $chf_12+$usd_28+$chf_14, Money->new( CHF=>26, USD=>28 ) );
  },
},

An example test suite:

use MoneyTest;
Test::Class->runtests;

which would send the following PerlTap output to STDOUT:

1..2
ok 1 - money bag
ok 2 - simple add

(assuming all the tests pass :-)

CategoryPerl, CategoryTesting


Loading...