Dave Rolsky > Test-Class-Moose > Test::Class::Moose::Report



Annotate this POD


View/Report Bugs
Module Version: 0.80   Source  


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


version 0.80


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

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


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 {

    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;
                      [ sort map { $_->name } @methods ],
                      "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';

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


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:


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


Integer. The number of test classes run.


Integer. The number of test instances run.


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


Integer. The number of tests run.


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


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


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


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


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.


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.


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


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


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 may be submitted through https://github.com/test-class-moose/test-class-moose/issues.

I am also usually active on IRC as 'drolsky' on irc://irc.perl.org.



This software is copyright (c) 2012 - 2016 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.

syntax highlighting: