How to find the reason for a risky test in PHPUnit

一世执手 提交于 2019-12-13 11:53:33

问题


From time to time I get a risky test in PHPUnit. Usually I can find the reason for a risky test. But the task can be time consuming, because I do not see any messages from PHPUnit, why a test is marked as risky. I only get something like this:

PHPUnit 4.4.5 by Sebastian Bergmann.

Configuration read from phpunit.xml.dist

R...................R.R...

Time: 11,91 seconds, Memory: 42,50Mb

OK, but incomplete, skipped, or risky tests!
Tests: 26, Assertions: 32, Risky: 3.        

Is there any option to tell PHPUnit to show messages or better something like stack traces to the code causing the risky flag? A complete list of causes for a risky test might prove helpful, too.


回答1:


This question deserves an answer, taken from comments above.

phpunit -v

This gives a short description of the reason for the risky test

 -v|--verbose              Output more verbose information.



回答2:


As of PHPUnit 5.3, the complete list of risky reasons:

  • A test makes no assertions, when being strict about tests that do nothing. (Source.)
  • A test marked with @todo, when being strict about TODO annotations. (Source.)
  • Using a function that operates on a resource, when running a small test and being strict about resource usage. (Source: thrown here based on this condition.)
  • Code does not close exactly the output buffers it opened. (Source.)
  • Code executes methods not explicitly listed in @covers for the test. (Source. A blog post on this scenario.)
  • Code manually throws a PHPUnit_Framework_RiskyTestError.
  • Code manually throws a PHPUnit_Framework_UnintentionallyCoveredCodeError.


来源:https://stackoverflow.com/questions/30163282/how-to-find-the-reason-for-a-risky-test-in-phpunit

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