Isi*_*ius 4 phpunit unit-testing
我只是在学习单元测试.这个PHP代码
class Foo {
public function bar($arg) {
throw new InvalidArgumentException();
}
}
Run Code Online (Sandbox Code Playgroud)
...
class FooTest extends PHPUnit_Framework_TestCase {
public function testBar() {
$this->setExpectedException('InvalidArgumentException');
$dummy = Foo::bar();
}
}
Run Code Online (Sandbox Code Playgroud)
Failed asserting that exception of type "PHPUnit_Framework_Error_Warning" matches expected exception "InvalidArgumentException".从phpunit 失败了.如果在Foo::bar()测试中放置了任何值,那么它当然可以按预期工作.有没有办法测试空参数?或者我是否错误地尝试为不应该在单元测试范围内的事物创建测试?