简体   繁体   English

PhpUnit 内联数据提供程序

[英]PhpUnit inline DataProvider

Is there a way to specify the test parameters directly in the annotation ?有没有办法直接在注释中指定测试参数? Something like this :像这样的事情:

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

Because it can be useful when the DataProvider is used only once with simple data set.因为当 DataProvider 仅对简单数据集使用一次时,它会很有用。

Thanks to Sebastian Bergmann, the solution is to use@testWith :感谢 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 4.8 中

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM