我有一组为 Jenkins 生成 JUnit 输出的脚本。
我执行的代码看起来像这样(这只是一个片段,所以你明白了):
#!/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']);
当我用解释器运行它时,我得到以下输出:
<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>
这里的主要问题是 JUnit 输出似乎弄错了时间。根据 sleep(2) 指令,它应该报告 2s。
有没有办法让 JUnit 文件中的时间正确?