Help-Site Computer Manuals
Software
Hardware
Programming
Networking
  Algorithms & Data Structures   Programming Languages   Revision Control
  Protocols
  Cameras   Computers   Displays   Keyboards & Mice   Motherboards   Networking   Printers & Scanners   Storage
  Windows   Linux & Unix   Mac

Test::Unit::Lite
Unit testing without external dependencies

Test::Unit::Lite - Unit testing without external dependencies


NAME

Test::Unit::Lite - Unit testing without external dependencies


SYNOPSIS

Bundling the the Test::Unit::Lite manpage as a part of package distribution:


  perl -MTest::Unit::Lite -e bundle

Running all test units:


  perl -MTest::Unit::Lite -e all_tests

Using as a replacement for Test::Unit:


  package FooBarTest;

  use Test::Unit::Lite;   # unnecessary if module isn't directly used

  use base 'Test::Unit::TestCase';

  sub new {

      my $self = shift()->SUPER::new(@_);

      # your state for fixture here

      return $self;

  }

  sub set_up {

      # provide fixture

  }

  sub tear_down {

      # clean up after test

  }

  sub test_foo {

      my $self = shift;

      my $obj = ClassUnderTest->new(...);

      $self->assert_not_null($obj);

      $self->assert_equals('expected result', $obj->foo);

      $self->assert(qr/pattern/, $obj->foobar);

  }

  sub test_bar {

      # test the bar feature

  }


DESCRIPTION

This framework provides lighter version of the Test::Unit manpage framework. It implements some of the the Test::Unit manpage classes and methods needed to run test units. The the Test::Unit::Lite manpage tries to be compatible with public API of the Test::Unit manpage. It doesn't implement all classes and methods at 100% and only those necessary to run tests are available.

The the Test::Unit::Lite manpage can be distributed as a part of package distribution, so the package can be distributed without dependency on modules outside standard Perl distribution. The the Test::Unit::Lite manpage is provided as a single file.

Bundling the the Test::Unit::Lite manpage as a part of package distribution

The the Test::Unit::Lite manpage framework can be bundled to the package distribution. Then the the Test::Unit::Lite manpage module is copied to the inc directory of the source directory for the package distribution.


FUNCTIONS

bundle
Copies the Test::Unit::Lite manpage modules into inc directory. Creates missing subdirectories if needed. Silently overwrites previous module if was existing.

all_tests
Creates new test runner for the Test::Unit::Lite::AllTests manpage suite which searches for test units in t/tlib directory.


CLASSES

the Test::Unit::TestCase manpage

This is a base class for single unit test module. The user's unit test module can override the default methods that are simple stubs.

The MESSAGE argument is optional and is included to the default error message when the assertion is false.

new
The default constructor which just bless an empty anonymous hash reference.

set_up
This method is called at the start of test unit processing. It is empty method and can be overrided in derived class.

tear_down
This method is called at the end of test unit processing. It is empty method and can be overrided in derived class.

list_tests
Returns the list of test methods in this class.

fail([MESSAGE])
Immediate fail the test.

assert(ARG [, MESSAGE])
Checks if ARG expression returns true value.

assert_null(ARG [, MESSAGE])
assert_not_null(ARG [, MESSAGE])
Checks if ARG is defined or not defined.

assert_equals(ARG1, ARG2 [, MESSAGE])
assert_not_equals(ARG1, ARG2 [, MESSAGE])
Checks if ARG1 and ARG2 are equals or not equals. If ARG1 and ARG2 look like numbers then they are compared with '==' operator, otherwise the string 'eq' operator is used.

assert_num_equals(ARG1, ARG2 [, MESSAGE])
assert_num_not_equals(ARG1, ARG2 [, MESSAGE])
Force numeric comparition.

assert_str_equals(ARG1, ARG2 [, MESSAGE])
assert_str_not_equals(ARG1, ARG2 [, MESSAGE])
Force string comparition.

assert(qr/PATTERN/, ARG [, MESSAGE])
assert_matches(qr/PATTERN/, ARG [, MESSAGE])
assert_does_not_match(qr/PATTERN/, ARG [, MESSAGE])
Checks if ARG matches PATTER regexp.

assert_deep_equals(ARG1, ARG2 [, MESSAGE])
assert_deep_not_equals(ARG1, ARG2 [, MESSAGE])
Check if reference ARG1 is a deep copy of reference ARG2 or not. The references can be deep structure. If they are different, the message will display the place where they start differing.

the Test::Unit::TestSuite manpage

This is a base class for test suite, which groups several test units.

empty_new([NAME])
Creates a fresh suite with no tests.

new([CLASS | TEST])
Creates a test suite from unit test name or class. If a test suite is provided as the argument, it merely returns that suite. If a test case is provided, it extracts all test case methods (see the Test::Unit::TestCase manpage->list_test) from the test case into a new test suite.

name
Contains the name of the current test suite.

units
Contains the list of test units.

add_test([TEST_CLASSNAME | TEST_OBJECT])
Adds the test object to a suite.

count_test_cases
Returns the number of test cases in this suite.

run
Runs the test suite and output the results as TAP report.

the Test::Unit::TestRunner manpage

This is the test runner which outputs text report about finished test suite.

new([$fh_out [, $fh_err]])
The constructor for whole test framework. Its optional parameters are filehandles for standard output and error messages.

fh_out
Contains the filehandle for standard output.

fh_err
Contains the filehandle for error messages.

suite
Contains the test suite object.

print_header
Called before running test suite.

print_error
Called after test unit is failed.

print_pass
Called after test unit is passed.

print_footer
Called after running test suite.

start(TEST_SUITE)
Starts the test suite.

the Test::Unit::Result manpage

This object contains the results of test suite.

new
Creates a new object.

messages
Contains the array of result messages. The single message is a hash which contains:
test
the test unit name,

type
the type of message (PASS or ERROR),

message
the text of message.

errors
Contains the number of collected errors.

passes
Contains the number of collected passes.

add_error(TEST, MESSAGE)
Adds an error to the report.

add_pass(TEST, MESSAGE)
Adds a pass to the report.

the Test::Unit::HarnessUnit manpage

This is the test runner which outputs in the same format that the Test::Harness manpage expects (Test Anything Protocol). It is derived from the Test::Unit::TestRunner manpage.

the Test::Unit::Debug manpage

The empty class which is provided for compatibility with original the Test::Unit manpage framework.

the Test::Unit::Lite::AllTests manpage

The test suite which searches for test units in t/tlib directory.


COMPATIBILITY

the Test::Unit::Lite manpage should be compatible with public API of the Test::Unit manpage. The the Test::Unit::Lite manpage also has some known incompatibilities:

  • The test methods are sorted alphabetically.

  • It implements new assertion method: assert_deep_not_equals.

  • Does not support ok, assert(CODEREF, @ARGS) and multi_assert.


EXAMPLES

t/tlib/SuccessTest.pm

This is the simple unit test module.


  package SuccessTest;

  use strict;

  use warnings;

  use base 'Test::Unit::TestCase';

  sub test_success {

    my $self = shift;

    $self->assert(1);

  }

  1;

t/all_tests.t

This is the test script for the Test::Harness manpage called with ``make test''.


  #!/usr/bin/perl

  

  use strict;

  use warnings;

  

  use lib 'inc', 'lib';

  

  use Test::Unit::Lite;

  

  local $SIG{__WARN__} = sub { require Carp; Carp::confess "Warning: $_[0]" };

  

  Test::Unit::HarnessUnit->new->start('Test::Unit::Lite::AllTests');

t/test.pl

This is the optional script for calling test suite directly.


  #!/usr/bin/perl

  

  use strict;

  use warnings;

  

  use File::Basename ();

  

  BEGIN {

      chdir File::Basename::dirname(__FILE__) or die "$!";

      chdir '..' or die "$!";

  }

  

  use lib 'inc', 'lib';

  

  use Test::Unit::Lite;

  

  local $SIG{__WARN__} = sub { require Carp; Carp::confess "Warning: $_[0]" };

  

  all_tests;

This is perl equivalent of shell command line:


  perl -Iinc -Ilib -MTest::Unit::Lite -w -e all_tests


SEE ALSO

the Test::Unit manpage, the Test::Unit::TestCase manpage, the Test::Unit::TestSuite manpage, the Test::Unit::Assert manpage, the Test::Unit::TestRunner manpage, the Test::Unit::HarnessUnit manpage.


TESTS

The the Test::Unit::Lite manpage was tested as a the Test::Unit manpage replacement for following distributions: the Test::C2FIT manpage, the XAO::Base manpage, the Exception::Base manpage.


BUGS

If you find the bug or need new feature, please report it.


AUTHOR

Piotr Roszatycki <dexter@debian.org>


LICENSE

Copyright (C) 2007 by Piotr Roszatycki <dexter@debian.org>.

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

Programminig
Wy
Wy
yW
Wy
Programming
Wy
Wy
Wy
Wy