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

如何有效地拆分大型phpunit测试套件?,phpunit,test-suite,Phpunit,Test Suite,我使用phpunit的testsuites特性来组织测试。我这样做是为了以后能够并行运行测试 对于不同的目录,这是相对直接的。例如,我可以将测试套件按捆绑包进行拆分 <testsuite name="bundle-one"> <directory>tests/BundleOne</directory> </testsuite> <testsuite name="bundle-two"> <directory>

我使用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>

测试/BundleOne
测试/捆绑服务
测试/捆绑树
但现在我只有一个目录(服务),其中包含几十个子文件夹。我可以手动为这个文件夹制作几个测试套件。但在我看来,这是一个软弱的解决方案。因为如果我提到testsuites中的每个子文件夹,并且这些文件夹被重命名或删除,testsuites可能会很容易崩溃

我的想法是使用某种正则表达式来选择要包含在一个testsuite中的一系列子文件夹,并为另一个testsuite选择另一系列文件夹

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

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

测试/服务/{A-M}
测试/服务/{A-M}

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

我不确定是否有一种方法可以“即时”完成这项工作,但您可以自动从reg ex创建这些捆绑包:

在composer.json中:

 "scripts": {
    "make-phpunit-bundles": "php path/to/myscript.php"
},
在运行测试之前:

php composer.phar make-phpunit-bundles
myscript.php:

//Iterate/scan your directories, build and write the phpunit.xml file 
//based on the regular expressions you want

更简单的解决方案可能是筛选测试:

# Only include test classes beginning with the letter A-M
phpunit --filter '/^[A-M]/'

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

你需要进行实验,以得到一个均匀的分割。i、 e.如果所有测试都以
A-M
之间的字符开始,那么这将不起作用


用PHPUnit 5.4.6测试。我就是这么做的。效果很好:)
# Only include test classes beginning with the letter N-Z
phpunit --filter '/^[N-Z]/'