LoginSignup
15
14

More than 5 years have passed since last update.

Circle CIで一定量のカバレッジに行かなかったらテストを落とす。

Last updated at Posted at 2014-05-27

CircleCIで一定量のcoverageに達しない場合はテストを落として、デプロイしない用にする。

前提

  • railsで開発を行っている。
  • gem simplecovを導入している。
  • rspecを導入している(他のテストツールでも多分大丈夫)

CircleCI自体はそのような機能は持っていない。下記問い合わせの返信内容。

We don't have anything built-in to prevent deploys when the test coverage is low. However, it looks like you're using simlecov. You can configure simplecov to fail the tests if the coverage is not high enough: https://github.com/colszowka/simplecov#minimum-coverage. We won't deploy if the tests fail.

解決方法

SimpleCovの設定でminimum_covarageを指定する。
SimpleCov.minimum_coverage 90

具体的には、spec#spec_helper.rbに下記のように設定した。

spec_helper.rb
require 'simplecov'
require 'simplecov-rcov'
if ENV['CIRCLE_ARTIFACTS']
  dir = File.join("..", "..", "..", ENV['CIRCLE_ARTIFACTS'], "coverage")
  SimpleCov.coverage_dir(dir)
end

SimpleCov.minimum_coverage 90
SimpleCov.formatter = SimpleCov::Formatter::RcovFormatter
SimpleCov.start do
  add_filter 'spec'
  add_filter 'vendor'
  add_filter 'features'
end

ENV["RAILS_ENV"] ||= 'test'
require File.expand_path("../../config/environment", __FILE__)
require 'rspec/rails'
require 'rspec/autorun'
require 'factory_girl'
~
~
~

circle CIでcovarageが低いと下記の用にエラーが出る。その後デプロイはされない。(minimum_coverageを100に設定してる)

Coverage (95.24%) is below the expected minimum coverage (100.00%).
((bundle exec rspec "" "" "spec" --format "progress")) returned exit code 2

15
14
0

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