Tbpgr Blog

Employee Experience Engineer tbpgr(てぃーびー) のブログ

Circle CI のテストで Crystal のテストレポートを生成する

alt

Crystal のプロジェクトでテスト結果をCircle CIで取り扱いたい場合についてまとめます。

サンプルコード

FizzBuzzのコードで検証します

テスト対象のコード

require "./crystal_ci_test/*"

module CrystalCiTest
  class FizzBuzz
    def self.call(number)
      puts
      case
      when number%15==0 then "FizzBuzz"
      when number%5==0 then "Buzz"
      when number%3==0 then "Fizz"
      else number.to_s
      end
    end
  end
end

テストコード

require "./spec_helper"

describe CrystalCiTest::FizzBuzz do
  describe "fizzbuzz" do
    it "FizzBuzz" do
      CrystalCiTest::FizzBuzz.call(15).should eq("FizzBuzz")
    end
    it "Buzz" do
      CrystalCiTest::FizzBuzz.call(5).should eq("Buzz")
    end
    it "Fizz" do
      CrystalCiTest::FizzBuzz.call(3).should eq("Fizz")
    end
    it "Other" do
      CrystalCiTest::FizzBuzz.call(1).should eq("1")
    end

  end
end

設定

circle.yml の設定

dependencies:
  cache_directories:
    - "crystal-0.18.7-1"
  pre:
    - if [[ ! -e crystal-0.18.7-1 ]]; then wget https://github.com/crystal-lang/crystal/releases/download/0.18.7/crystal-0.18.7-1-linux-x86_64.tar.gz && tar xvfz crystal-0.18.7-1-linux-x86_64.tar.gz; fi
test:
  pre:
    - crystal-0.18.7-1/bin/crystal deps
  override:
    - crystal-0.18.7-1/bin/crystal spec --junit_output $CIRCLE_TEST_REPORTS/junit/test-results.xml

テストレポート未設定

f:id:tbpg:20160903072111p:plain

テスト成功時

f:id:tbpg:20160903072117p:plain

テスト失敗時

f:id:tbpg:20160903072123p:plain

外部資料