Perl 将TAP::Formatter::JUnit与有趣的测试一起使用?
我对我的Mojolicious应用程序进行了很多测试,这些测试都很好,现在我正试图将Mojolicious输出到JUnitXML。我已经找到了Perl 将TAP::Formatter::JUnit与有趣的测试一起使用?,perl,testing,mojolicious,Perl,Testing,Mojolicious,我对我的Mojolicious应用程序进行了很多测试,这些测试都很好,现在我正试图将Mojolicious输出到JUnitXML。我已经找到了TAP::Formatter::JUnit,它看起来正是我想要的,但我没有掌握如何获得令人愉快的测试(仅由我的应用程序根级别的script/site.pl test运行)来使用它 如果我想把它输出到JUnit XML中,我是否遗漏了一些显而易见的东西,或者我不能使用Mojolicous的内置测试功能?我查看了一下,它正在使用Test::harnese运行测
TAP::Formatter::JUnit
,它看起来正是我想要的,但我没有掌握如何获得令人愉快的测试(仅由我的应用程序根级别的script/site.pl test运行)来使用它
如果我想把它输出到JUnit XML中,我是否遗漏了一些显而易见的东西,或者我不能使用Mojolicous的内置测试功能?我查看了一下,它正在使用Test::harnese
运行测试套件。模块被包装在TAP::Harness
上,我们需要设置其formatter
参数。我还没有找到任何方法来推送参数(有一些环境变量,如harnese\u OPTIONS
,但它们不允许参数)
你能做的就是实施。我创建了新的Mojolicous应用程序,并根据上面的指南在应用程序启动中添加了新的命令名称空间:
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);
与
运行它作为
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>
希望这有帮助。提出了一个问题,要求能够指定格式化程序。@VirtualWolf-很高兴这有帮助。提出这个问题可能会改进test命令的性能,因此我们可以不费吹灰之力地使用替代的格式化程序。
<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>