有没有办法直接在注释中指定测试参数?像这样的事情:
/**
* @dataProvider [[0, 0, 0], [0, 1, 1], [1, 0, 1]]
*/
public function testAdd($a, $b, $expected)
{
$this->assertEquals($expected, $a + $b);
}
因为当 DataProvider 仅对简单数据集使用一次时,它会很有用。
最佳答案
感谢 Sebastian Bergmann,解决方案是使用 @testWith
:
/**
* @testWith [0, 0, 0]
* [0, 1, 1]
* [1, 1, 2]
* [1, 0, 1]
*/
public function testAdd($a, $b, $c)
{
$this->assertEquals($c, $a + $b);
}
关于PhpUnit 内联数据提供程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36470000/