TAP ::线束时序问题与TAP :: Formatter :: JUnit [英] TAP::Harness timing issue with TAP::Formatter::JUnit

查看:166
本文介绍了TAP ::线束时序问题与TAP :: Formatter :: JUnit的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一组脚本,这些脚本为Jenkins生成JUnit输出.

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>

这里的主要问题是JUnit输出似乎计时不正确.根据sleep(2)指令,它应该报告为2s.

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.

是否有一种方法可以正确获取JUnit文件中的计时?

Is there a way to get the timing in the JUnit file right ?

推荐答案

我对使它起作用很感兴趣,但这是到目前为止我所取得的成功.拆分为单独的测试(.t)文件时,效果似乎更好.

I'm interested in getting this to work, but here's what I've had success with so far. It seems to work better when split out into a separate test (.t) file.

测试运行器看起来像这样:

The test runner looks like this:

#!/usr/bin/env perl                                                                                                                            
use strict;                                                                                                                                    
use warnings;                                                                                                                                  
use Test::More;                                                                                                                                
use TAP::Harness;                                                                                                                              
use Test::Builder;   

my $harness = TAP::Harness->new({
    formatter_class => 'TAP::Formatter::JUnit',
    merge           => 1,
    verbosity       => 1,
    normalize       => 1,
    color           => 1,
    timer           => 1,
});

$harness->runtests('simple.t');

,测试文件如下所示:

#!/usr/bin/env perl
use Test::More;

ok(sleep(2), "Sleep test");

done_testing;

以下是输出:

<testsuites>
  <testsuite failures="0"
             errors="0"
             time="2.05175995826721"
             tests="1"
             name="simple_t">
    <testcase time="2.04811692237854" name="1 - Sleep test"></testcase>
    <testcase time="0.00308394432067871" name="(teardown)" />
    <system-out><![CDATA[ok 1 - Sleep test
1..1
]]></system-out>
    <system-err></system-err>
  </testsuite>
</testsuites>

这篇关于TAP ::线束时序问题与TAP :: Formatter :: JUnit的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆