I have a set of scripts that produces a JUnit output for Jenkins.
The code I execute looks like this (this is just a snippet so you get the idea) :
#!/usr/bin/env perl
use strict;
use warnings;
use Test::More;
use TAP::Harness;
use Test::Builder;
my $runner = sub {
my ($harness,$test) = @_;
sleep(2);
my $builder = Test::Builder->new;
$builder->reset;
$builder->output( \my ($out) );
$builder->failure_output( \$out );
$builder->todo_output( \$out );
$builder->is_eq($test,'test', 'Test is test');
done_testing();
return $out;
};
my $h = TAP::Harness->new( {
formatter_class => 'TAP::Formatter::JUnit',
merge => 1,
exec => $runner,
verbosity => 1,
timer => 1,
});
$h->runtests( ['test']);
When I run this with the interpreter, I get the following output :
<testsuites>
<testsuite failures="0"
errors="0"
time="0.000340938568115234"
tests="1"
name="test">
<testcase time="9.79900360107422e-05" name="1 - Test is test"></testcase>
<testcase time="8.29696655273438e-05" name="(teardown)" />
<system-out><![CDATA[ok 1 - Test is test
1..1
]]></system-out>
<system-err></system-err>
</testsuite>
</testsuites>
The main issue here is that the JUnit output seems to get the timing wrong. As per the sleep(2) instruction, it should have reported 2s.
Is there a way to get the timing in the JUnit file right ?