【发布时间】:2011-05-09 04:01:10
【问题描述】:
有没有比$this->assertTrue(false) 更正式的强制phpunit 失败的方法?
【问题讨论】:
标签: phpunit
有没有比$this->assertTrue(false) 更正式的强制phpunit 失败的方法?
【问题讨论】:
标签: phpunit
我相信这应该在测试用例中起作用:
$this->fail('Message');
【讨论】:
fail 将产生一个不错的堆栈跟踪
$this->fail()的相反功能吗?
return;。
return;,你可能还需要@doesNotPerformAssertions注解。
是的,有办法,
$this->fail("your message");
如果你想查看你失败的页面
print_r(getResponse()->getContent());
【讨论】:
getResponse() 是框架特定的功能,可能不普遍可用。
另一种方法(在编写测试工具时特别有用)是:
use PHPUnit_Framework_ExpectationFailedException as PHPUnitException;
try {
// something here
} catch (SpecificException $e) {
// force a fail:
throw new PHPUnitException("This was not expected.");
}
【讨论】: