Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Coverage not working properly #755

Closed
ghost opened this issue Nov 4, 2019 · 10 comments
Closed

Coverage not working properly #755

ghost opened this issue Nov 4, 2019 · 10 comments

Comments

@ghost
Copy link

ghost commented Nov 4, 2019

Hi, new RoR guy here.

I'm using ruby 2.6.3p62 (latest) and Rails 6.0.0 (also latest) but this gem (using latest) seems to not show test coverage properly. Below is the setup and the result:

Gemfile:

group :test do
  ...
  gem 'simplecov'
  ..
end

test/test_helper.rb:

require 'simplecov'

SimpleCov.start 'rails'

ENV['RAILS_ENV'] ||= 'test'

require_relative '../config/environment'
require 'rails/test_help'
...

app/controllers/pages_controller.rb: (an example controller)

class PagesController < ApplicationController
  def index
    @title = "Hello World!"
  end
end

test/controllers/pages_controller_test.rb: (an example controller test)

require 'test_helper'

class PagesControllerTest < ActionDispatch::IntegrationTest
  test "should get homepage" do
    get root_path
    assert_select "body", "Hello World!"
  end
end

COVERAGE output:

+----------+----------------------------------------------+-------+--------+---------+
| coverage | file                                         | lines | missed | missing |
+----------+----------------------------------------------+-------+--------+---------+
|   0.00%  | app/controllers/pages_controller.rb          | 5     | 5      | 1-5     |
+----------+----------------------------------------------+-------+--------+---------+
@ghost
Copy link
Author

ghost commented Nov 8, 2019

After some trial and error, it seems that commenting out the parallel testing line (37) still is the solution to fix this problem:

class ActiveSupport::TestCase
  # Run tests in parallel with specified workers
  # parallelize(workers: :number_of_processors);
  ...
end

@ghost
Copy link
Author

ghost commented Nov 12, 2019

Closing this as there seems to be no activity at the moment.

@ghost ghost closed this as completed Nov 12, 2019
@worace
Copy link

worace commented Dec 17, 2019

I ran into this as well on Rails 6.0.0 and Simplecov 0.17.1. Fixed for the moment by disabling parallel testing.

The README interestingly claims this is supported:

As of 0.8.0, SimpleCov should correctly recognize parallel_tests and supplement your test suite names with their corresponding test env numbers. SimpleCov locks the resultset cache while merging, ensuring no race conditions occur when results are merged.

So I wonder if there were some changes in how parallel testing is handled in recent Rails versions that caused a regression here.

@PragTob
Copy link
Collaborator

PragTob commented Dec 17, 2019

@worace rails built their own parallel testing thingy... so far we only integrate with parallel_tests as in the parallel_tests gem. Making it work with rails 6.0 parallel tests is on the roadmap 👌

@PragTob
Copy link
Collaborator

PragTob commented Dec 17, 2019

Also sorry hadn't seen this issue or rather.. when I looked it was already closed so I thought it was resolved.

@worace
Copy link

worace commented Dec 18, 2019

Ah, makes sense. Thanks for the explanation. I have been out of rails for a bit and did not realize they were different things.

@GURVARINDER
Copy link

@PragTob Any updates on this issue? Has this been resolved in the latest version?

@PragTob
Copy link
Collaborator

PragTob commented Sep 11, 2020

@GURVARINDER no I didn't have time yet to work on tests parallel test execution

@pdfrod
Copy link

pdfrod commented Nov 5, 2021

Can I suggest adding to the documentation that Rails parallel tests is not supported at the moment? I just wasted a lot of time trying to figure out why my code coverage was incorrect.

@dtgay
Copy link

dtgay commented Jan 11, 2024

You can get simplecov working with Rails test parallelization with the fix here: #718 (comment)

This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants