如何在 PHPUnit 中查找风险测试的原因
How to find the reason for a risky test in PHPUnit
有时我会在 PHPUnit 中进行有风险的测试。通常我可以找到风险测试的原因。但这项任务可能很耗时,因为我没有看到来自 PHPUnit 的任何消息,为什么测试被标记为有风险。我只得到这样的东西:
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.
是否有任何选项可以告诉 PHPUnit 显示消息或更好的东西,比如对导致风险标志的代码的堆栈跟踪?
风险测试的完整原因列表也可能会有所帮助。
这个问题值得回答,摘自上面的评论。
phpunit -v
这里简要描述了风险测试的原因
-v|--verbose Output more verbose information.
自 PHPUnit 5.3 起,风险原因的完整列表:
- 当对什么都不做的测试严格时,测试不做任何断言。 (Source.)
- 标记为
@todo
的测试,对 TODO 注释严格。 (Source.)
- 使用 function that operates on a resource, when running a small test and being strict about resource usage. (Source: thrown here based on this condition.)
- 代码没有关闭完全它打开的输出缓冲区。 (Source.)
- 代码执行未在
@covers
中明确列出的测试方法。 (Source. A blog post 在这种情况下。)
- 代码手动抛出
PHPUnit_Framework_RiskyTestError
.
- 代码手动抛出
PHPUnit_Framework_UnintentionallyCoveredCodeError
.
有时我会在 PHPUnit 中进行有风险的测试。通常我可以找到风险测试的原因。但这项任务可能很耗时,因为我没有看到来自 PHPUnit 的任何消息,为什么测试被标记为有风险。我只得到这样的东西:
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.
是否有任何选项可以告诉 PHPUnit 显示消息或更好的东西,比如对导致风险标志的代码的堆栈跟踪? 风险测试的完整原因列表也可能会有所帮助。
这个问题值得回答,摘自上面的评论。
phpunit -v
这里简要描述了风险测试的原因
-v|--verbose Output more verbose information.
自 PHPUnit 5.3 起,风险原因的完整列表:
- 当对什么都不做的测试严格时,测试不做任何断言。 (Source.)
- 标记为
@todo
的测试,对 TODO 注释严格。 (Source.) - 使用 function that operates on a resource, when running a small test and being strict about resource usage. (Source: thrown here based on this condition.)
- 代码没有关闭完全它打开的输出缓冲区。 (Source.)
- 代码执行未在
@covers
中明确列出的测试方法。 (Source. A blog post 在这种情况下。) - 代码手动抛出
PHPUnit_Framework_RiskyTestError
. - 代码手动抛出
PHPUnit_Framework_UnintentionallyCoveredCodeError
.