Laravelのテスト結果をかっこよく!
Laravelのテスト結果をこんな感じに視覚的に見たくて、導入してみました。
走り書きです
環境
Windows10
Laravel 5.6.39
Allure Frameworkのallure2を利用します。
レポートツールの用意
scoop install allure
※Macはbrewで導入できるみたい。
scoopの導入:https://scoop.sh/
allure2のGitHub:https://github.com/allure-framework/allure2
allure-framework/allure-phpunitの導入
$ composer require --dev allure-framework/allure-phpunit
※今回のLaravelのバージョンだと以下のバージョン
composer require --dev allure-framework/allure-phpunit^1.4
レポートツールのPHPUnit用アダプターパッケージ。(ほかの言語も対応しているみたい)
allure-phpunitのGitHub:https://github.com/allure-framework/allure-phpunit
phpunit.xmlに追記
testsuiteタグの次ぐらいにいれておく
<listeners>
<listener class="Yandex\Allure\PhpUnit\AllurePhpUnit" file="vendor/allure-framework/allure-phpunit/src/Yandex/Allure/PhpUnit/AllurePhpUnit.php">
<arguments>
<string>build/allure-results</string> <!-- XML files output directory -->
<boolean>true</boolean> <!-- Whether to delete previous results on rerun -->
<array> <!-- A list of custom annotations to ignore (optional) -->
<element key="0">
<string>someCustomAnnotation</string>
</element>
</array>
</arguments>
</listener>
</listeners>
※Duskのxmlにも追記
laravel/build/allure-results
にレポートファイル(xml等)が出力される
※4行目で変更可能
GitHubの説明:https://github.com/allure-framework/allure-phpunit#installation--usage
結果を視覚化
PowerShell等で、laravel/build
に移動し、
allure generate -c
を実行する(-c
はclean
オプション)
laravel/build/allure-report
に展開される。
結果を見る
展開されたファイルをchromeで開くもCORSに引っかかる。
そのため、CORSを回避するためにchromeのショートカットを作成し、リンク先に以下を追記
--disable-web-security --user-data-dir="C://Chrome dev session"
作成したショートカットのchromeを実行して、build\allure-report\index.html
をD&D
参考Qiita:https://qiita.com/shika-e/items/808ccdd047133315b95c
テスト実装時
テストを書く際に、レポートで分かりやすくできようなアノテーションも可能で、
タイトル、ディスクリプション、重要度、パラメータ情報、ストーリー、フィーチャー、と色々あるし書いていくほうが良い。
アノテーションの説明:https://github.com/allure-framework/allure-phpunit#main-features
参考リンクまとめ
Author And Source
この問題について(Laravelのテスト結果をかっこよく!), 我々は、より多くの情報をここで見つけました https://qiita.com/ijohnny/items/be60456746a48464ddca著者帰属:元の著者の情報は、元の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 .