PHPUnit error: Missing argument 1 for with dataProvider
PHPUnit error: Missing argument 1 for with dataProvider
我有以下测试脚本:
class testTest extends PHPUnit_Framework_TestCase
{
public function provider() {
return [
[1,false],
[2,true]
];
}
/**
* @test
* @provider provider
*/
public function test_test($num, $expected) {
$actual = $num%2 ? false : true;
$this->assertEquals($actual, $expected);
}
}
每当我运行这个我得到错误:
1) testTest::test_test
Missing argument 1 for testTest::test_test()
我的测试服中还有其他未使用 dataProvider 的测试,它们工作正常。我该如何解决这个问题?
将@provider
更改为@dataProvider
,例如
/**
* @dataProvider provider
*/
public function test_test($num, $expected) {
$actual = $num%2 ? false : true;
$this->assertEquals($actual, $expected);
}
阅读文档:
https://phpunit.de/manual/current/en/appendixes.annotations.html#appendixes.annotations.dataProvider
PS:您在 assertEquals 中将参数弄错了。应该是:
$this->assertEquals($expected, $actual);
再次:https://phpunit.de/manual/current/en/appendixes.assertions.html#appendixes.assertions.assertEquals
我有以下测试脚本:
class testTest extends PHPUnit_Framework_TestCase
{
public function provider() {
return [
[1,false],
[2,true]
];
}
/**
* @test
* @provider provider
*/
public function test_test($num, $expected) {
$actual = $num%2 ? false : true;
$this->assertEquals($actual, $expected);
}
}
每当我运行这个我得到错误:
1) testTest::test_test
Missing argument 1 for testTest::test_test()
我的测试服中还有其他未使用 dataProvider 的测试,它们工作正常。我该如何解决这个问题?
将@provider
更改为@dataProvider
,例如
/**
* @dataProvider provider
*/
public function test_test($num, $expected) {
$actual = $num%2 ? false : true;
$this->assertEquals($actual, $expected);
}
阅读文档: https://phpunit.de/manual/current/en/appendixes.annotations.html#appendixes.annotations.dataProvider
PS:您在 assertEquals 中将参数弄错了。应该是:
$this->assertEquals($expected, $actual);
再次:https://phpunit.de/manual/current/en/appendixes.assertions.html#appendixes.assertions.assertEquals