How to make PHPUnit fail on risky tests

我是研究僧i 提交于 2019-12-23 17:37:12

问题


I want PHPUnit to fail if one or more test is considered as risky. Actually:

PHPUnit 5.3.4 by Sebastian Bergmann and contributors.

..RRR..                                                         7 / 7 (100%)

Time: 2.83 seconds, Memory: 26.00Mb

OK, but incomplete, skipped, or risky tests!
Tests: 7, Assertions: 137, Risky: 3.

It says "OK, but incomplete", so my tests did not fail (and can be shipped in case of continous delivery). Is there any way to have a "fail" status? I want my test global status considered as failed on risky test, don't know if it's possible.


回答1:


There is a --stop-on-risky option that can be enabled from the command line or configured in the phpunit.xml.

The problem with this is that the run process wont execute all the tests. I'm not aware of a direct way of considering risky tests as failed.

The behaviour you want to obtain was proposed but not accepted, so don't expect to be implemented:

https://github.com/sebastianbergmann/phpunit/issues/1612




回答2:


You can use the --fail-on-risky flag when calling the PHPUnit executable, or set the failOnRisky="true" attribute to the <phpunit> element in phpunit.xml.

In contrary to --stop-on-risky/stopOnRisky="true" this will not stop the test suite when PHPUnit encounters a risky test, but it will make PHPUnit exit with a non-zero status code, as it would when one of the tests fails.



来源:https://stackoverflow.com/questions/38303547/how-to-make-phpunit-fail-on-risky-tests

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!