PHPUnitを分割実行する
はじめに
PHPUnitを分割実行して、実行後にログとカバレッジをそれぞれマージする方法です。
分割実行することでメモリ使用量を下げることができるので、大規模なプロジェクトでPHPUnitを実行するときなどに有用です。
必要なもの
phpcov
コードカバレッジのマージに必要です。
Composerでインストールします。
merge-phpunit-xml.php
ログのマージに必要です。
ダウンロードして適当な場所に配置します。
Composerでphpcovをインストールしていれば、必要なパッケージも一緒にインストールされているはずなので、下記のように書き換えてvendor/autoload.php
ファイルをインクルードすれば動くはずです。
@@ -1,7 +1,6 @@
#!/usr/bin/env php
<?php
-require 'SebastianBergmann/FinderFacade/autoload.php';
-require 'TheSeer/fDOMDocument/autoload.php';
+require_once __DIR__ . '/vendor/autoload.php';
use SebastianBergmann\FinderFacade\FinderFacade;
use TheSeer\fDOM\fDOMDocument;
実行権限も与えておきます。
chmod 755 merge-phpunit-xml.php
PHPUnitの分割実行
分割前に下記のように実行していたとすると、
phpunit --log-junit /tmp/test-reports/phpunit/phpunit.result.xml --coverage-html coverage.html --coverage-xml coverage.xml
分割後は下記のように実行します。
phpunit --group group1 --log-junit /tmp/test-reports/phpunit/phpunit.result.01.xml --coverage-php /tmp/test-reports/phpunit/coverage.txt/coverage.01.txt
phpunit --group group2 --log-junit /tmp/test-reports/phpunit/phpunit.result.02.xml --coverage-php /tmp/test-reports/phpunit/coverage.txt/coverage.02.txt
この例だと、グループで分割しています。
ログのマージ
merge-phpunit-xml.php /tmp/test-reports/phpunit /tmp/test-reports/phpunit/phpunit.result.xml
merge-phpunit-xml.php /tmp/test-reports/phpunit /tmp/test-reports/phpunit/phpunit.result.xml
第1引数にマージ前のログが置いてあるディレクトリ、第2引数にマージ後のログを出力するパスを指定します。
この例だと、/tmp/test-reports/phpunit/phpunit.result.01.xml
ファイルと/tmp/test-reports/phpunit/phpunit.result.02.xml
ファイルがマージされて、/tmp/test-reports/phpunit/phpunit.result.xml
ファイルが生成されます。
カバレッジのマージ
phpcov merge --html /tmp/test-reports/phpunit/coverage.html --xml /tmp/test-reports/phpunit/coverage.xml /tmp/test-reports/phpunit/coverage.txt
phpcov merge --html /tmp/test-reports/phpunit/coverage.html --xml /tmp/test-reports/phpunit/coverage.xml /tmp/test-reports/phpunit/coverage.txt
マージしたカバレッジを色々なフォーマットで出力可能です。
この例だと、/tmp/test-reports/phpunit/coverage.txt/coverage.01.txt
ファイルと/tmp/test-reports/phpunit/coverage.txt/coverage.02.txt
ファイルがマージされて、/tmp/test-reports/phpunit/coverage.html
ディレクトリと/tmp/test-reports/phpunit/coverage.xml
ディレクトリが生成されます。
参考
Author And Source
この問題について(PHPUnitを分割実行する), 我々は、より多くの情報をここで見つけました https://qiita.com/ngmy/items/609a2407ddf52d2b1102著者帰属:元の著者の情報は、元のURLに含まれています。著作権は原作者に属する。
Content is automatically searched and collected through network algorithms . If there is a violation . Please contact us . We will adjust (correct author information ,or delete content ) as soon as possible .