Better reporting for your test suite

It's very poorly documented, but Test::Class::Moose also has reporting built in.

Here's how diag() all test classes from slowest to fastest, with time information:

use Test::Most;
use Test::Class::Moose::Load 't/lib';    # assumes your T:C:M tests are here

my $test_suite = Test::Class::Moose->new;
$test_suite->runtests;

my $report = $test_suite->test_reporting;

# sort from slowest to fastest
my @classes =
  sort { $b->time->real <=> $a->time->real } $report->all_test_classes;
foreach my $class (@classes) {
    my $name = $class->name;
    my $duration = $class->time->duration; # a human-readable version
    diag "$name runtime: $duration";                                                                                                       
}

You can do that at a test method level, too. Plus, the time is broken down into system, user, and real time.

Leave a comment

About Ovid

user-pic Have Perl; Will Travel. Freelance Perl/Testing/Agile consultant. Photo by http://www.circle23.com/. Warning: that site is not safe for work. The photographer is a good friend of mine, though, and it's appropriate to credit his work.