3
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

SimpleCovとRails 6のMinitest

Posted at

カバレッジツールSimpleCov をRails 6のデフォルトのテスト(Minitest)で使ってみたところ、カバー率が0になりました。

Coverage report generated for RSpec to /Users/kazuto/projects/kazubon/blog-rails6-vuejs/coverage. 0 / 299 LOC (0.0%) covered.

Rails 6から導入されたパラレルテストの影響らしく、test_helper.rbでparallelizeをコメントアウトすると、SimpleCovがカバー率を出しました。

test/test_helper.rb
class ActiveSupport::TestCase
  include FactoryBot::Syntax::Methods

  # parallelize(workers: :number_of_processors)

  # fixtures :all
end

SimpleCovのGithubのIssueに、パラレルテストを使いつつカバー率を出す方法を見つけた人がいました。SimpleCov本体ではまだ対策されていないようです。

test/test_helper.rb
class ActiveSupport::TestCase
  include FactoryBot::Syntax::Methods

  parallelize(workers: :number_of_processors)

  parallelize_setup do |worker|
    SimpleCov.command_name "#{SimpleCov.command_name}-#{worker}"
  end

  parallelize_teardown do |worker|
    SimpleCov.result
  end

  # fixtures :all
end

これでうまくいくのですが、MinitestなのにRspecと表示されるのがちょっと気になります。Rspecも入れているせいか。

Coverage report generated for RSpec, RSpec-0, RSpec-1, RSpec-2, RSpec-3 to /Users/kazuto/projects/kazubon/blog-rails6-vuejs/coverage. 187 / 210 LOC (89.05%) covered.
3
2
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
3
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?