4

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 ?

4

1 に答える 1

0

これを機能させることに興味がありますが、これまでに成功したことは次のとおりです。.t別のテスト ( ) ファイルに分割すると、うまく機能するようです。

テスト ランナーは次のようになります。

#!/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>
于 2015-01-17T02:36:07.887 に答える