NAME

Test::Extreme - A perlish unit testing framework

SYNOPSIS

# In your code module ModuleOne.pm

sub foo { return 23 };
sub bar { return 42 };

# In your test module ModuleOneTest.pm

use Test::Extreme;

sub test_foo { assert_equals foo, 23 }    
sub test_bar { assert_equals bar, 42 }    

# To run these tests on the command line type

perl -MModuleOneTest -e run_tests

# If you have tests in several modules (say in
# ModuleOneTest.pm, ModuleTwoTest.pm and ModuleThreeTest.pm,
# create AllTests.pm containing precisely the following:

use ModuleOneTest;
use ModuleTwoTest;
use ModuleThreeTest;

1;

# To run all of these tests on the command line type

perl -MAllTests -e run_tests

# If you have tests in different namespaces you can run them
# by typing (for example)

perl -MAllTests -e 'run_tests "namespace1", "namespace2"'


# Also take a look at Test/Extreme.pm which includes its own
# unit tests for how to instrument a module with unit tests

DESCRIPTION

Test::Extreme is a perlish port of the xUnit testing
framework. It is in the spirit of JUnit, the unit testing
framework for Java, by Kent Beck and Erich Gamma. Instead of
porting the implementation of JUnit we have ported its spirit
to Perl.

The target market for this module is perlish people
everywhere who value laziness above all else.

Test::Extreme is especially written so that it can be easily
and concisely used from Perl programs without turning them
into Java and without inducing object-oriented nightmares in
innocent Perl programmers. It has a shallow learning curve.
The goal is to adopt the unit testing idea minus the OO
cruft, and to make the world a better place by promoting the
virtues of laziness, impatience and hubris.

You test a given unit (a script, a module, whatever) by using
Test::Extreme, which exports the following routines into your
namespace:

assert $x            - $x is true
assert_true $x       - $x is true
assert_false $x      - $x is not true
assert_passed        - the last eval did not die ($@ eq "")
assert_failed        - the last eval caused a die ($@ ne "")
assert_some $x       - $x is true
assert_none          - $x is false
assert_equals $x, $y - recursively tests arrayrefs, hashrefs
                       and strings to ensure they have the same 
                       contents
assert_contains $string, $list 
                     - $list contains $string assert_subset 
                       $element_list, $list - $element_list is 
                       a subset of $list (both are arrayrefs)
assert_is_array $x   - $x is an arrayref
assert_is_hash $x    - $x is a hashref
assert_is_string $x  - $x is a scalar
assert_size N, $list - the arrayref contains N elements
assert_keys ['k1', 'k2'], $hash 
                     - $hash contains k1, k2 as keys
run_tests            - run all tests in package main
run_tests NS1, NS2, ...
                     - run all tests in package main, NS1,
                       NS2, and so on

For an example on how to use these assert take a look at
Test/ExtremeTest.pm which shows different ways of using these
asserts.

Currently this requires that all your tests live in the
main:: namespace. If you are not sure what that means things
will probably just work seamlessly.

The function run_tests finds all functions that start with
the word test (preceded by zero or more underscores) and runs
them one at a time.

Running the tests generates a status line (a "." for every
successful test run, or an "F" for any failed test run), a
summary result line ("OK" or "FAILURES!!!") and zero or more
lines containing detailed error messages for any failed
tests.

AUTHOR

Copyright (c) 2002 Asim Jalis, <asimjalis@acm.org>.

All rights reserved. This program is free software; you can
redistribute it and/or modify it under the same terms as Perl
itself.

SEE ALSO

- Test::Unit
- Test::SimpleUnit