我正在尝试扩展PHPUnit的功能。
我想扩展它关于如何允许测试断言预期Exception
被抛出的行为。
我通过扩展PHPUnit_Framework_TestCase
完成了这项工作,如下所示:
class Improved_TestCase extends PHPUnit_Framework_TestCase {
//...
}
问题是,我现在需要编写一个测试,证明如果没有抛出@expectedException
,测试将会失败。
例如,我想表明以下测试会失败:
/**
* I want to write a TestTest that passes when these tests would fail
*/
class FooTest extends Improved_TestCase {
/**
* @expectedException Exception
*/
function testFooThrowsAnnotatedException()
{
Foo::thisWillNotThrowAnException();
}
function testFooThrowsSetException()
{
$this->setExpectedException('Exception');
Foo::thisWillNotThrowAnException();
}
}
上述测试应该失败。但有些人我需要编写一个测试,当上述测试失败时会通过。
我已尝试查看PHPUnit's tests source code,但我不了解它如何或在何处测试预期的异常测试的工作情况。
据我所知,我最好的猜测是@expectedException
behaviour is tested here,但它没有意义,因为如果PHPUnit工作正常,那些测试会失败!< / p>
答案 0 :(得分:0)
测试它的代码是here in TestCaseTest.php:
<!DOCTYPE html><html><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>T</title>
</head><body>noaeuvpraoisevuapnrsoievunapsoirevuanpsiorvunapeisovrnupaisovurapiosevraes<br></body></html>