我在使用命令行运行测试时遇到了问题:如果我像这样运行phpunit:
phpunit -–no-configuration -–filter testAdd DataTest DataProviderTest.php
它正常工作。 但是我们使用一个正则表达式来精确指定要测试的方法的名称:
phpunit -–no-configuration -–filter /::testAdd$/ DataTest DataProviderTest.php
很遗憾,第二种方法没有起作用。 源代码如下:
<?php
class DataTest extends PHPUnit_Framework_TestCase
{
/**
* @dataProvider provider
*/
public function testAdd($a, $b, $c)
{
$this->assertEquals($c, $a + $b);
}
public function provider()
{
return array(
array(0, 0, 0),
array(0, 1, 1),
array(1, 0, 1),
array(1, 1, 3)
);
}
}
?>
phpunit --filter "/::test.+( with data set #.+)?$/"
或类似的方式非常酷,可以运行所有带有数据提供程序的测试 ;) - edorian.*
以捕获任何数据集。 - David Harkness--filter
的新语法更加简单易懂。https://phpunit.de/manual/current/en/textui.html#textui.examples.filter-patterns - martin