LoginSignup
2

More than 5 years have passed since last update.

CircleCIは複数の JUnit 形式の XML ファイルをマージしてくれる

Last updated at Posted at 2017-06-08

結論はタイトルの通りです。
2.0 は試してないのでわからないですが、そっちでも同様かもしれません。
2.0でも同様にマージされます!

CircleCI 1.0では JUnit 形式の XML ファイルを $CIRCLE_TEST_REPORTS のディレクトリ内に出力することで、2.0では store_test_results ステップを使い XML ファイルの入っているディレクトリを CircleCI 側に保存すると、テスト結果をいい感じに表示してくれます。

こういうやつ。

image.png

時には一度に複数のテストフレームワークを実行したいこともあると思いますが、そういう場合どうすれば良いのか調べて見ました。

ドキュメントによるとこのように書かれています。

If you have multiple JUnit test reports from running more than one test suite or runner, you can merge them together using the third-party NodeJS CLI tool, junit-merge.

This tool can combine the reports into a single file that our test summary system can parse and give you correct test totals.

もしや junit-merge なるコマンドを使って手動でマージしないといけない? と思いましたが、試して見たところしなくても問題なさそうでした。

こんな感じの circle.yml を用意します。

test:
  override:
    - bundle exec rspec --format RspecJunitFormatter --out $CIRCLE_TEST_REPORTS/rspec_1.xml spec/test_1_spec.rb
    - bundle exec rspec --format RspecJunitFormatter --out $CIRCLE_TEST_REPORTS/rspec_2.xml spec/test_2_spec.rb

これは全然実用的な例でないですが、RSpec を 1 ファイルごとに 1 回ずつで合計 2 回実行し、それぞれ別のファイル名で JUnit 形式の XML を出力します。

すると CircleCI 上では見事マージした結果が出力されていました。 (上記のスクショの通り)

めでたしめでたし

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2