douzhang3898 2010-10-14 20:01
浏览 78
已采纳

如何包装PHPUnit来控制命令行报告?

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

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

  • 写回答

3条回答 默认 最新

  • dqypcghd381390 2010-10-15 06:09
    关注

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

    They work like this:

    ]> 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
    

    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.

    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).

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

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

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 mmocr的训练错误,结果全为0
  • ¥15 python的qt5界面
  • ¥15 无线电能传输系统MATLAB仿真问题
  • ¥50 如何用脚本实现输入法的热键设置
  • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
  • ¥30 深度学习,前后端连接
  • ¥15 孟德尔随机化结果不一致
  • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀