我看着Mojolicious::Command::test,它使用Test::Harness
来运行测试套件。该模块覆盖了TAP::Harness
,我们需要设置其参数formatter
。我还没有找到任何方法来推送参数(有环境变量如HARNESS_OPTIONS
,但他们不允许参数)。
你可以做的是实施new command for your application。我创建新Mojolicious应用,上述应用程序启动时加入每引导新的命令名称空间:
push @{$self->commands->namespaces}, 'JUnitTest::Command';
然后我复制Mojolicious::Command::test
成JUnit::Command::testjunit
和替换run
方法的最后几行:
$ENV{HARNESS_OPTIONS} //= 'c';
require Test::Harness;
Test::Harness::runtests(sort @args);
与
require TAP::Harness;
my $harness = TAP::Harness->new({
formatter_class => 'TAP::Formatter::JUnit',
lib => \@INC,
merge => 1,
});
$harness->runtests(sort @args);
运行它,
perl script/junit_test testjunit
导致了这样的输出:
<testsuites>
<testsuite failures="0" errors="0" tests="3" name="t_basic_t">
<testcase name="1 - get /"></testcase>
<testcase name="2 - 200 OK"></testcase>
<testcase name="3 - content is similar"></testcase>
<system-out><![CDATA[1..3
ok 1 - get/
ok 2 - 200 OK
ok 3 - content is similar
]]></system-out>
<system-err></system-err>
</testsuite>
</testsuites>
希望这有助于。
来源
2013-02-17 07:58:52
bvr
完美的工作,非常感谢你! :) – VirtualWolf 2013-02-17 10:36:43
提出了一个问题[这里](https://github.com/kraih/mojo/issues/454)有能力指定格式化程序。 – VirtualWolf 2013-02-17 10:46:26
@VirtualWolf - 很高兴这有帮助。提出这个问题可能会导致测试命令的改进,所以我们可以毫不费力地使用其他格式化器。 – bvr 2013-02-17 13:06:25