Class-Object
view release on metacpan or search on metacpan
t/lib/Test/More.pm view on Meta::CPAN
use Test::More tests => $Num_Tests;
# or
use Test::More qw(no_plan);
# or
use Test::More qw(skip_all);
BEGIN { use_ok( 'Some::Module' ); }
require_ok( 'Some::Module' );
# Various ways to say "ok"
ok($this eq $that, $test_name);
is ($this, $that, $test_name);
isnt($this, $that, $test_name);
like($this, qr/that/, $test_name);
skip { # UNIMPLEMENTED!!!
ok( foo(), $test_name );
is( foo(42), 23, $test_name );
} $how_many, $why;
todo { # UNIMPLEMENTED!!!
ok( foo(), $test_name );
is( foo(42), 23, $test_name );
} $how_many, $why;
pass($test_name);
fail($test_name);
# Utility comparison functions.
eq_array(\@this, \@that);
eq_hash(\%this, \%that);
eq_set(\@this, \@that);
# UNIMPLEMENTED!!!
my @status = Test::More::status;
=head1 DESCRIPTION
If you're just getting started writing tests, have a look at
Test::Simple first.
This module provides a very wide range of testing utilities. Various
ways to say "ok", facilities to skip tests, test future features
and compare complicated data structures.
=head2 I love it when a plan comes together
Before anything else, you need a testing plan. This basically declares
how many tests your script is going to run to protect against premature
failure.
The prefered way to do this is to declare a plan when you C<use Test::More>.
use Test::More tests => $Num_Tests;
There are rare cases when you will not know beforehand how many tests
your script is going to run. In this case, you can declare that you
have no plan. (Try to avoid using this as it weakens your test.)
use Test::More qw(no_plan);
In some cases, you'll want to completely skip an entire testing script.
use Test::More qw(skip_all);
Your script will declare a skip and exit immediately with a zero
(success). L<Test::Harness> for details.
=head2 Test names
By convention, each test is assigned a number in order. This is
largely done automatically for you. However, its often very useful to
assign a name to each test. Which would you rather see:
ok 4
not ok 5
ok 6
or
ok 4 - basic multi-variable
not ok 5 - simple exponential
ok 6 - force == mass * acceleration
The later gives you some idea of what failed. It also makes it easier
to find the test in your script, simply search for "simple
exponential".
All test functions take a name argument. Its optional, but highly
suggested that you use it.
=head2 I'm ok, you're not ok.
The basic purpose of this module is to print out either "ok #" or "not
ok #" depending on if a given test succeeded or failed. Everything
else is just gravy.
All of the following print "ok" or "not ok" depending on if the test
succeeded or failed. They all also return true or false,
respectively.
=over 4
=item B<ok>
ok($this eq $that, $test_name);
This simply evaluates any expression (C<$this eq $that> is just a
simple example) and uses that to determine if the test succeeded or
failed. A true expression passes, a false one fails. Very simple.
For example:
ok( $exp{9} == 81, 'simple exponential' );
ok( Film->can('db_Main'), 'set_db()' );
ok( $p->tests == 4, 'saw tests' );
( run in 3.076 seconds using v1.01-cache-2.11-cpan-75ffa21a3d4 )