如何包装PHPUnit来控制命令行报告? [英] How to wrap PHPUnit to control command line reporting?

查看:79
本文介绍了如何包装PHPUnit来控制命令行报告?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

因此,我有很多PHPUnit测试(它们实际上是作为PHPUnit测试运行的Selenium测试).当我从命令行运行它们时,我会在测试完成时得到这种报告:

So I've got a lot of PHPUnit tests (they are actually Selenium tests running as PHPUnit tests). When I run them from the command line, I get this sort of reporting as the tests complete:

..E..F..E.FF...

然后,我必须等到所有测试完成运行后,才能告诉我错误和失败的内容.我希望能够对此进行控制,以便可以做一些更有用的报告.例如:

Then I have to wait until all the tests finish running before it will tell me the errors and what failed. I would like to be able to control this so I can do some more useful reporting. For example:

testLogin ....... passed
testFoobar ...... failed
    - Failed asserting that foo = true on line 123
testBazbat ...... passed

如何控制PHPUnit如何显示结果?

How can I get control over how PHPUnit displays the results?

推荐答案

PHPUnit具有一些命令行参数来控制输出格式.对您来说最有用的是--testdox和--tap

PHPUnit has a few command line parameters to control the output format. The most useful ones for your are --testdox and --tap

他们是这样工作的:

]> phpunit --tap FooTest.php 
TAP version 13
not ok 1 - Failure: FooTest::test_add
  ---
  message: fark
  severity: fail
  ...
ok 2 - FooTest::test_exists
ok 3 - FooTest::test_show_html
ok 4 - FooTest::test_show_array
ok 5 - FooTest::test_show_empty
ok 6 - FooTest::test_find
1..6


]> phpunit --testdox FooTest.php 
PHPUnit 3.5.0 by Sebastian Bergmann.

Foo
 [ ] test add
 [x] test exists
 [x] test show html
 [x] test show array
 [x] test show empty
 [x] test find

如您所见,--testdox并未显示失败原因,它的使用就像一种规范生成器.但是--tap非常接近.

As you can see --testdox does not show the failure reason, its ment to be used like a kind of specification generator. But --tap comes pretty close.

您总是可以编写自己的测试侦听器-一个实现PHPUnit_Framework_Testlistener接口的自定义类(具有startTest,endTest,addFailure,addError等方法;名称非常不言自明,将为发生的事件调用相应的代码当您的测试套件运行时).

And you can always write your own test listener - a custom class that implements PHPUnit_Framework_Testlistener interface (has methods like startTest, endTest, addFailure, addError etc; the names are pretty self-explanatory, respective code will be called for events that happen when your testsuite runs).

使用xml配置文件将此类代码连接到phpunit中.

Such code is hooked up into phpunit using the xml configuration file.

可以在此处查看此类自定义侦听器的一个好示例: http://raphaelstolt.blogspot.com/2010/06/growling-phpunits-test-status.html

One good example of such custom listener can be viewed here: http://raphaelstolt.blogspot.com/2010/06/growling-phpunits-test-status.html

这篇关于如何包装PHPUnit来控制命令行报告?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆