2015-08-24 31 views
0

我使用phpunit的testsuites功能來組織我的測試。我這樣做是爲了能夠在稍後並行運行測試。如何有效地拆分大型phpunit測試套件?

這對於不同的目錄來說是相對直接的。因此,我可以通過捆綁分解測試套件。

<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> 

但現在我有一個單一的目錄(服務),其中包含幾十個子文件夾。我可以手動製作幾個測試套件我們的這個文件夾。但在我看來,這將是一個薄弱的解決方案。因爲如果我提到它們中的每個子文件夾以及文件夾被重命名或刪除,測試套件就會很容易中斷。

我的想法是使用某種正則表達式來選擇要包含在一個測試套件中的子文件夾的範圍,以及另一個測試套件的另一個範圍的文件夾。

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

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

我找不到任何關於我的想法的文檔。有人可能有這個想法嗎? :-)

回答

0

林不知道是否有辦法做到這一點「上即時」,但你可以自動創建從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 
+0

THX。我是那麼做的。工作得很好:) – stijink

2

更簡單的解決方案可能是篩選測試:

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

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

假設所有的測試類開始以大寫字母。

您需要嘗試才能獲得均勻分割。即如果所有的測試都以A-M之間的字符開始,那麼這將不起作用。

測試使用PHPUnit 5.4.6