perl TAP 测试:如何从 TAP::Formatter::HTML 输出获取失败测试的计数?
我使用 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
为什么不从 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.
App::Prove::History
App::Prove::History
回答我自己的问题:
我所要做的就是使用运行测试的返回值。
Answering my own question:
All I had to do was using the return value of runtests.