Christian Lemburg


Test::Unit::Assert - unit testing framework assertion class


    # this class is not intended to be used directly, 
    # normally you get the functionality by subclassing from 
    # Test::Unit::TestCase

    use Test::Unit::TestCase;

    # more code here ...

    $self->assert($your_condition_here, $your_optional_message_here);

    # or, for regular expression comparisons:

    $self->assert(qr/some_pattern/, $result);

    # or, for functional style coderef tests:

    $self->assert(sub {$_[0] == $_[1] || die "Expected $_[0], got $_[1]"},
                  1, 2); 

    # or, for old style regular expression comparisons:

    $self->assert(scalar("foo" =~ /bar/), $your_optional_message_here);


This class is used by the framework to assert boolean conditions that determine the result of a given test. The optional message will be displayed if the condition fails. Normally, it is not used directly, but you get the functionality by subclassing from Test::Unit::TestCase.

You can also pass in a regular expression object or a coderef as first argument to get additional functionality. Note that this is the recommended approach to testing regular expression matching.

If you want to use the "old" style for testing regular expression matching, please be aware of this: the arguments to assert() are evaluated in list context, e.g. making a failing regex "pull" the message into the place of the first argument. Since this is ususally just plain wrong, please use scalar() to force the regex comparison to yield a useful boolean value.

Copyright (c) 2000 Christian Lemburg, <>.

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

Thanks go to the other PerlUnit framework people: Brian Ewins, Cayte Lindner, J.E. Fritz, Zhon Johansen.

Thanks for patches go to: Matthew Astley, David Esposito, Piers Cawley.