PhpUnit内联DataProvider

5

有没有一种方法可以直接在注释中指定测试参数?就像这样:

 /**
 * @dataProvider [[0, 0, 0], [0, 1, 1], [1, 0, 1]]
 */
public function testAdd($a, $b, $expected)
{
    $this->assertEquals($expected, $a + $b);
}

因为在只使用简单数据集时,DataProvider仅使用一次时可能很有用。

2个回答

15

感谢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);
}

4

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接