在PHPUnit中更改测试方法的名称

时间:2014-03-04 15:38:06

标签: php phpunit

有没有办法更改PHPUnit用于查找测试的method的名称?我想更改默认的test前缀以使用BDD样式,而是以it开头。

我的搜索只提供了使用phpunit.xml配置更改文件名称的方法,

<directory prefix="test-" suffix=".php">./tests/</directory>

感谢。

1 个答案:

答案 0 :(得分:4)

我做了一些挖掘,我在Framework\TestSuite.php找到了:

public static function isTestMethod(ReflectionMethod $method)
{
    if (strpos($method->name, 'test') === 0) {
        return TRUE;
    }

    // @scenario on TestCase::testMethod()
    // @test     on TestCase::testMethod()
    return strpos($method->getDocComment(), '@test')     !== FALSE ||
           strpos($method->getDocComment(), '@scenario') !== FALSE;
}

因此,名称以"test"开头,或者注释为@test@scenario。我已确认注释有效。

正如您所看到的,没有配置传递给此函数,所以我认为您不能配置自定义前缀。