Softpedia
 


LINUX CATEGORIES:



GLOBAL PAGES >>
NEWS ARCHIVE >>
SOFTPEDIA REVIEWS >>
MEET THE EDITORS >>
WEEK'S BEST
  • Linux Kernel 3.9.2 / 3....
  • LibreOffice 3.6.6 / 4.0.3
  • MPlayer 1.1.1
  • systemd 204
  • Arch Linux 2013.05.01
  • Blender 2.67
  • KDE Software Compilatio...
  • CrunchBang Linux Stable...
  • Elementary OS 0.1 / 0.2...
  • SystemRescueCd 3.6.0
  • Home > Linux > Programming > Libraries

    Test::Unit::TestCase 0.14

    Download button

    No screenshots available
    Downloads: 379  View global page NEW!  Tell us about an update
    User Rating:
    Rated by:
    NOT RATED
    0 user(s)
    Developer:

    License / Price:

    Last Updated:

    Category:
    Christian Lemburg | More programs
    Perl Artistic License / FREE
    June 14th, 2007, 04:05 GMT
    ROOT / Programming / Libraries

     Read user reviews (0)  Refer to a friend  Subscribe

    Test::Unit::TestCase description

    Test::Unit::TestCase is a unit testing framework base class.

    Test::Unit::TestCase is a unit testing framework base class.

    SYNOPSIS

    package FooBar;
    use base qw(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 {
    # test the foo feature
    }
    sub test_bar {
    # test the bar feature
    }

    (Taken from the JUnit TestCase class documentation)

    A test case defines the "fixture" (resources need for testing) to run multiple tests. To define a test case:

    implement a subclass of TestCase
    define instance variables that store the state of the fixture
    initialize the fixture state by overriding set_up()
    clean-up after a test by overriding tear_down().

    Each test runs in its own fixture so there can be no side effects among test runs. Here is an example:

    package MathTest;
    use base qw(Test::Unit::TestCase);

    sub new {
    my $self = shift()->SUPER::new(@_);
    $self->{value_1} = 0;
    $self->{value_2} = 0;
    return $self;
    }

    sub set_up {
    my $self = shift;
    $self->{value_1} = 2;
    $self->{value_2} = 3;
    }

    For each test implement a method which interacts with the fixture. Verify the expected results with assertions specified by calling $self->assert() with a boolean value.

    sub test_add {
    my $self = shift;
    my $result = $self->{value_1} + $self->{value_2};
    $self->assert($result == 5);
    }

    Once the methods are defined you can run them. The normal way to do this uses reflection to implement run_test. It dynamically finds and invokes a method. For this the name of the test case has to correspond to the test method to be run. The tests to be run can be collected into a TestSuite. The framework provides different test runners, which can run a test suite and collect the results. A test runner either expects a method suite() as the entry point to get a test to run or it will extract the suite automatically.

    If you do not like the rather verbose backtrace that appears when a test fails, you can use the quell_backtrace() method. You will get any message provided, but not the backtrace.

    Requirements:

    · Perl



    Product's homepage

    Requirements:

    · Perl

      


    TAGS:

    unit testing | testing framework | Perl class | Test::Unit::TestCase | unit | testing

    Go to top

    WindowsGamesDriversMacLinuxScriptsMobileHandheldNews

    SUBMIT PROGRAM   |   ADVERTISE   |   GET HELP   |   SEND US FEEDBACK   |   RSS FEEDS   |   UPDATE YOUR SOFTWARE   |   ROMANIAN FORUM