NAME

Test::Class::Moose::Report - Test information for Test::Class::Moose

VERSION

version 0.67

SYNOPSIS

use Test::Class::Moose::Runner;

my $runner = Test::Class::Moose::Runner->new;
$runner->runtests;
my $report = $runner->test_report;

DESCRIPTION

When working with larger test suites, it's useful to have full reporting information available about the test suite. The reporting features of Test::Class::Moose allow you to report on the number of test class instances and methods run (and number of tests), along with timing information to help you track down which tests are running slowly. You can even run tests on your report information:

#!/usr/bin/env perl
use lib 'lib';
use Test::Most;
use Test::Class::Moose::Load qw(t/lib);
my $test_suite = Test::Class::Moose->new;

subtest 'run the test suite' => sub {
    $test_suite->runtests;
};

my $report = $test_suite->test_report;
my $duration = $report->time->duration;
diag "Test suite run time: $duration";

foreach my $class (@c) {
    my $class_name = $class->name;
    subtest "report for class:$class_name" => sub {
        ok !$class->is_skipped, "class:$class_name was not skipped";
        ok $class->passed, "class:$class_name passed";

        my @i = $class->all_test_instances;
        is scalar @i, 1, "tested one instance for $class_name";

        foreach my $instance (@i) {
            my $instance_name = $instance->name;
            subtest "report for instance:$instance_name" => sub {
                ok !$instance->is_skipped,
                  "instance:$instance_name was not skipped";
                ok $instance->passed, "instance:$instance_name passed";

                my @methods = $instance->all_test_methods;
                is_deeply
                  [ sort map { $_->name } @methods ],
                  $expected_methods{$class_name},
                  "instance:$instance_name ran the expected methods";

                foreach my $method (@methods) {
                    my $method_name = $method->name;
                    subtest "report for method:$method_name" => sub {
                        ok !$method->is_skipped,
                          "$method_name was not skipped";
                        cmp_ok $method->num_tests_run, '>', 0,
                          '... and some tests should have been run';
                        _test_report_time($method);
                    };
                }
            };
        }
    };
}

Reporting is currently in alpha. The interface is not guaranteed to be stable.

METHODS

The top level report object for the whole test suite is returned from the Test::Class::Moose::Runner object's test_report method.

This object provides the following methods:

all_test_classes

Returns an array of Test::Class::Moose::Report::Class objects.

num_test_classes

Integer. The number of test classes run.

num_test_instances

Integer. The number of test instances run.

num_test_methods

Integer. The number of test methods that the runner tried to run.

num_tests_run

Integer. The number of tests run.

current_class

Returns the Test::Class::Moose::Report::Class for the test class currently being run, if it exists. This may return undef.

current_instance

Returns the Test::Class::Moose::Report::Instance for the test class instance currently being run, if it exists. This may return undef.

current_method

Returns the Test::Class::Moose::Report::Method for the test method currently being run, if one exists. This may return undef.

time

Returns a Test::Class::Moose::Report::Time object. This object represents the duration of the entire test suite.

timing_data

Returns a complex nested hashref containing timing data for the entire test run. This is primarily intended for serialization or shipping the data to code in other languages. If you want to analyze timing data from the same process as the test report, you might as well just use the Perl API.

See "TIMING DATA STRUCTURE" for an example of the full structure.

At the top level of the data structure are two keys, time and class. The time key is replicated through different levels of the structure. It always contains three keys:

{   real   => 1.0001,
    system => 0.94,
    user   => 0.1,
}

The class key in turn contains a hashref keyed by class names. For each class, there is a time key and an instance key.

The instance key contains a hashref keyed on instance names. For each instance, there is a hashref with time, control, and method keys.

The control key contains a hashref keyed on the control method names, test_startup and test_shutdown. Each of those keys contains a hashref containing time key.

The method keys are the names of the methods that were run for that test instance. Each of those keys is in turn a hashref containing control and time keys. The control key contains a hashref keyed on the control method names, test_setup and test_teardown.

TRUSTED METHODS

The following Test::Class::Moose::Report methods are for internal use only and are called by Test::Class::Moose. They are included here for those who might want to hack on Test::Class::Moose.

_inc_test_methods

$statistics->_inc_test_methods;        # increments by 1
$statistics->_inc_test_methods($x);    # increments by $x

_inc_tests

$statistics->_inc_tests;        # increments by 1
$statistics->_inc_tests($x);    # increments by $x

TIMING DATA STRUCTURE

Here's an example of what the entire timing data structure looks like:

{   time => {
        real   => "90.2795791625977",
        system => "13.5419368743896",
        user   => 100
    },
    class => {
        "TestsFor::Basic" => {
            time => {
                real   => "37.7511978149414",
                system => "5.66267967224121",
                user   => "32.0885181427002"
            },
            instance => {
                "TestsFor::Basic" => {
                    time => {
                        real   => "27.4395942687988",
                        system => "4.11593914031982",
                        user   => "23.323655128479"
                    },
                    control => {
                        test_shutdown => {
                            time => {
                                real   => "0.240802764892578",
                                system => "0.0361204147338867",
                                user   => "0.204682350158691"
                            },
                        },
                        test_startup => {
                            time => {
                                real   => "0.360012054443359",
                                system => "0.0540018081665039",
                                user   => "0.306010246276855"
                            },
                        },
                    },
                    method => {
                        test_me => {
                            time => {
                                real   => "4.6992301940918",
                                system => "0.70488452911377",
                                user   => "3.99434566497803"
                            },
                            control => {
                                test_setup => {
                                    time => {
                                        real   => "0.510215759277344",
                                        system => "0.0765323638916016",
                                        user   => "0.433683395385742"
                                    },
                                },
                                test_teardown => {
                                    time => {
                                        real   => "0.269412994384766",
                                        system => "0.0404119491577148",
                                        user   => "0.229001045227051"
                                    },
                                },
                            },
                        },
                    },
                },
            },
        },
    },
}

BUGS

Please report any bugs or feature requests to bug-test-class-moose at rt.cpan.org, or through the web interface at http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Test-Class-Moose. I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.

SUPPORT

You can find documentation for this module with the perldoc command.

perldoc Test::Class::Moose

You can also look for information at:

AUTHORS

  • Curtis "Ovid" Poe <ovid@cpan.org>

  • Dave Rolsky <autarch@urth.org>

COPYRIGHT AND LICENSE

This software is copyright (c) 2012 - 2015 by Curtis "Ovid" Poe.

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