运行 phpunit 中的一个文件或地图

Run one file or map in phpunit

我正在使用 laravel 并且我已经编写了一些测试文件。但是我怎样才能只执行一个文件呢?例如,当我这样做时:phpunit tests/resulttesting/school/deleteSchoolForRealTest 它会抛出一个错误:

Cannot open file "tests/resulttesting/school/deleteSchoolForRealTest.php".

当我 运行 phpunit 时,它 运行 是我所有的测试。我怎样才能只执行一个文件夹?我在 mac。

你做的一切都正确。

1)

添加文件夹的第一种方法。 我的正确方法是:

phpunit tests/EWalletTest

当我忘记从“测试”文件夹开始时,我遇到了同样的错误

phpunit EWalletTest

我得到了

Cannot open file "EWalletTest.php".

2)

Filter 是另一种选择。 read here 示例:

phpunit --filter EWallet

Only runs tests whose name matches the given regular expression pattern.

意味着您将执行文件 EWalletTestEWalletFooTest 以及来自其他文件的测试用例,名称如 `test_EWallet_with_Australian_dollar.

使用过滤器选项

phpunit --filter=EWalletTest

使用phpunit.xml

@group 选项可用于 class 实体和方法。

class一个

/**
 * @group active
 * */
class ArrayShiftRightTest extends TestCase
{
}

class B

/**
 * @group inactive
 * */
class BinaryGapTest extends TestCase
{    
}

在phpunit.xml

<groups>
    <include>
        <group>active</group>
    </include>
    <exclude>
        <group>inactive</group>
    </exclude>
</groups>

属于active组的classes将被执行。