The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

    Test::Extreme - A Perlish unit testing framework

SYNOPSIS

    # In ModuleOne.pm combine unit tests with code

    package ModuleOne;
    use Test::Extreme;
    sub foo { return 23 };
    sub test_foo { assert_equals foo, 23 }    

    # at the end of the module 

    run_tests 'ModuleOne' if $0 =~ /ModuleOne\.pm$/;

    # To run the tests in this module on the command line type

    perl ModuleOne.pm

    # If you have tests in several modules (say in ModuleOne.pm,
    # ModuleTwo.pm and ModuleThree.pm, create test.pl containing
    # precisely the following:

    use ModuleOne;
    use ModuleTwo;
    use ModuleThree;

    run_tests 'ModuleOne', 'ModuleTwo', 'ModuleThree', 

    # Then run these tests on the command line with

    perl test.pl

    # If you prefer to get Perl's classic "ok/not ok" output use
    # replace run_tests with run_tests_as_script in all of the
    # above

    # 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_as_script  - run all tests in package main and emit
                           Perl's classic "ok/not ok" style output

    run_tests_as_script NS1, NS2, ...
                         - run all tests in package main, NS1,
                           NS2, and so on and emit Perl's classic 
                           "ok/not ok" style output

    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/Extreme.pm which includes it own unit tests and illustrates different ways of using these asserts.

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. It looks in the 'main' namespace by default and also looks in any namespaces passed to it as arguments.

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.

To get Perl's classic "ok/not ok" style output (which is useful for writing test scripts) use run_tests_as_script instead of run_tests.

AUTHOR

Asim Jalis <asimjalis@gmail.com>.

COPYRIGHT

Copyright 2002-2012 by Asim Jalis <asimjalis@gmail.com>.

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

See http://www.perl.com/perl/misc/Artistic.html.