如何有效地拆分大型 phpunit 测试套件?

sti*_*ink 3 phpunit test-suite

我使用 phpunit 的 testsuites 功能来组织我的测试。我这样做是为了以后能够并行运行测试。

对于不同的目录,这相对简单。因此,例如,我可以通过捆绑来拆分测试套件。

<testsuite name="bundle-one">
    <directory>tests/BundleOne</directory>
</testsuite>

<testsuite name="bundle-two">
    <directory>tests/BundleTwo</directory>
</testsuite>

<testsuite name="bundle-three">
    <directory>tests/BundleThree</directory>
</testsuite>
Run Code Online (Sandbox Code Playgroud)

但是现在我有一个包含数十个子文件夹的目录(服务)。我可以手动为这个文件夹制作几个测试套件。但在我看来,这将是一个薄弱的解决方案。因为如果我提到测试套件中的每个子文件夹并且文件夹被重命名或删除,测试套件可能很容易损坏。

我的想法是使用某种正则表达式来选择一系列子文件夹以包含在一个测试套件中,并为另一个测试套件选择另一范围的文件夹。

<testsuite name="services-AM">
    <directory>tests/services/{A-M}</directory>
</testsuite>

<testsuite name="services-NZ">
    <directory>tests/services/{A-M}</directory>
</testsuite>
Run Code Online (Sandbox Code Playgroud)

我找不到任何关于我的想法的文档。有人可能对此有想法吗?:-)

Tam*_*ama 5

一个更简单的解决方案可能是过滤你的测试:

# Only include test classes beginning with the letter A-M
phpunit --filter '/^[A-M]/'
Run Code Online (Sandbox Code Playgroud)

# Only include test classes beginning with the letter N-Z
phpunit --filter '/^[N-Z]/'
Run Code Online (Sandbox Code Playgroud)

假设您所有的测试类都以大写字母开头。

您将需要进行试验以获得均匀的分割。即,如果您的所有测试都以字符开头,A-M则这将不起作用。

用 PHPUnit 5.4.6 测试