perl TAP 测试:如何从 TAP::Formatter::HTML 输出获取失败测试的计数?

发布于 2024-10-01 04:25:29 字数 1367 浏览 2 评论 0原文

我使用 TAP::Formatter::HTML 运行一些 TAP 测试。

这个 CPAN 模块生成漂亮的动态 HTML 报告,但我想使用通过的测试、失败的测试等的数量 - 在所有测试完成后将它们插入数据库。

下面的代码不起作用。它不会向控制台打印任何内容。我承认,对于第 10 行及之后的行,我只是将 TAP::* 类的 POD 描述中的一些代码拼凑在一起。

在深入研究 Aggregator、Harmess 或 Formatter 类和子类的源代码之前,我最好问:

这里有人知道如何使该代码工作吗?

    my $cons = TAP::Formatter::Console->new();
    my $fmt = TAP::Formatter::HTML->new;

    $fmt->css_uris( \@css_uris )->inline_css($my_css)->js_uris($js_uris)->inline_js($inline_js);

    my $harness = TAP::Harness->new( { formatter => $fmt, merge => 1 } );

    $fmt->output_file($outfile);
    $harness->test_args(["--browser=$browser", "--config=$config"]);
    my $aggregator = TAP::Parser::Aggregator->new;
    $aggregator->start();
    $harness->runtests(@tests);


#    $harness->aggregate_tests( $aggregator, @tests );
   $aggregator->stop();
#    print $fmt->summary($aggregator);
    my $txt = $cons->summary( $aggregator ); 
    my $summary = <<'END_SUMMARY';
    Passed:  %s
    Failed:  %s
    Unexpectedly succeeded: %s
END_SUMMARY
    printf $summary,
           scalar $aggregator->passed,
           scalar $aggregator->failed,
           scalar $aggregator->todo_passed;

    #$failcount = sprintf("%03d", $harness->failures());
    print "summary: $txt\n";

I run some TAP Tests using TAP::Formatter::HTML.

This CPAN module generates beautiful dynamic HTML Reports, but I want to use the number of passed tests, failed tests etc - to insert them into a database after all tests completed.

The code below does not work. It prints nothing to the console. I admit, for lines 10 and after, I just have slapped together some code from the POD descriptions of the TAP::* classes.

Before I dive into the source code of Aggregator, Harmess or Formatter classes and subclasses, I better ask:

does anyone here know how to make this code work?

    my $cons = TAP::Formatter::Console->new();
    my $fmt = TAP::Formatter::HTML->new;

    $fmt->css_uris( \@css_uris )->inline_css($my_css)->js_uris($js_uris)->inline_js($inline_js);

    my $harness = TAP::Harness->new( { formatter => $fmt, merge => 1 } );

    $fmt->output_file($outfile);
    $harness->test_args(["--browser=$browser", "--config=$config"]);
    my $aggregator = TAP::Parser::Aggregator->new;
    $aggregator->start();
    $harness->runtests(@tests);


#    $harness->aggregate_tests( $aggregator, @tests );
   $aggregator->stop();
#    print $fmt->summary($aggregator);
    my $txt = $cons->summary( $aggregator ); 
    my $summary = <<'END_SUMMARY';
    Passed:  %s
    Failed:  %s
    Unexpectedly succeeded: %s
END_SUMMARY
    printf $summary,
           scalar $aggregator->passed,
           scalar $aggregator->failed,
           scalar $aggregator->todo_passed;

    #$failcount = sprintf("%03d", $harness->failures());
    print "summary: $txt\n";

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

So尛奶瓶 2024-10-08 04:25:29

为什么不从 TAP::Formatter::HTML 相同的源获取测试数据?它可能正在检查 Test::Builder 对象并从那里获取测试统计信息。 Test::Builder 对象是一个单例,因此在测试完成后很容易请求它的副本并从中提取数据以进行数据库插入,大约在同一时间生成漂亮的 HTML 报告。

Why not get the test data from the same source TAP::Formatter::HTML does? It is probably inspecting the Test::Builder object and getting the test statistics from there. The Test::Builder object is a singleton, so it is pretty easy to request a copy of it after your tests have been done and extract the data from it for DB insertion, at about the same time the pretty HTML reports are generated.

情仇皆在手 2024-10-08 04:25:29

回答我自己的问题:

   my $harness = TAP::Harness->new( { formatter => $fmt, merge => 1 } );
    $harness->test_args( [ "--browser=$browser", "--config=$h{config}" ] );
    my $agg = $harness->runtests(@tests);
    my $summary = <<'END_SUMMARY';
    Passed:    %s
    Failed:    %s
    Unexpectedly succeeded: %s
    To do:     %s
    Skipped:   %s
    Planned:   %s
    END_SUMMARY
    printf $summary, scalar $agg->passed,
           scalar $agg->failed,
           scalar $agg->todo_passed,
         scalar $agg->todo  ,
         scalar $agg->todo_passed,
         scalar $agg->skipped,
         scalar $agg->planned;

我所要做的就是使用运行测试的返回值。

Answering my own question:

   my $harness = TAP::Harness->new( { formatter => $fmt, merge => 1 } );
    $harness->test_args( [ "--browser=$browser", "--config=$h{config}" ] );
    my $agg = $harness->runtests(@tests);
    my $summary = <<'END_SUMMARY';
    Passed:    %s
    Failed:    %s
    Unexpectedly succeeded: %s
    To do:     %s
    Skipped:   %s
    Planned:   %s
    END_SUMMARY
    printf $summary, scalar $agg->passed,
           scalar $agg->failed,
           scalar $agg->todo_passed,
         scalar $agg->todo  ,
         scalar $agg->todo_passed,
         scalar $agg->skipped,
         scalar $agg->planned;

All I had to do was using the return value of runtests.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文