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

Minitest wrong coverage value #314

Closed
plribeiro3000 opened this issue Jul 3, 2014 · 4 comments
Closed

Minitest wrong coverage value #314

plribeiro3000 opened this issue Jul 3, 2014 · 4 comments

Comments

@plribeiro3000
Copy link

Im currently facing a problem i dont even know where to look. Im working on a project fog/fog-xenserver and i can't get simplecov to work on it.

It is resulting in 74.08% coverage when i have only 1 test and the lib is big, really big. I have tested both latest version (0.8.2) and the one stated on README (0.7.1).

Even if i remove require 'minitest/autorun' and no tests run, my coverage still 74.08%.

Ruby version : ruby 2.1.2p95 (2014-05-08 revision 45877) [x86_64-darwin13.0]
Minitest version : 4.7.5

In case it was something i did not properly configured, i have create a branch simplecov so you guys could check it.

I use rake to run my tests as you can see here

@bf4
Copy link
Collaborator

bf4 commented Jul 13, 2014

So, it's important understand how SimpleCov, and the stdlib Coverage lib it depends on works.

It tracks when code is evaluated for the first time (i.e. when loaded or run )

Thus, if you run SimpleCov.start, load a file, then run SimpleCov.result, you will see a certain amount of 'code coverage'. That is, running tests is a way to increase the coverage of a file above the coverage you get for just loading it.

In your test helper you have Dir[File.join(File.dirname(__FILE__), '../lib/**/*.rb')].sort.each { |f| require f } which loads all your ruby folders under lib. Thus, you see files 'covered' that weren't tested.

@plribeiro3000
Copy link
Author

Hey @bf4 , Thanks for taking the time to look at the project. 👍

@bf4
Copy link
Collaborator

bf4 commented Aug 3, 2014

I've been referencing this question quite a bit. If anyone wants to help put together a 'standard response' doc, that would be great. See e.g. the one nokogiri uses https://github.com/sparklemotion/nokogiri/blob/master/STANDARD_RESPONSES.md

@geekq
Copy link

geekq commented May 31, 2019

For me the key change was to require and start simplecov BEFORE minitest/autorun loads ./lib

# <BEGINNING OF test/test_helper.rb>
# Require and start simplecov BEFORE minitest/autorun loads ./lib to get correct
# test results. Otherwise lot of executed lines are not detected.
require 'simplecov'
SimpleCov.start do
  add_filter 'test'
end

require 'minitest/autorun'

class << Minitest::Test
  def test(name, &block)
...

I am maintaining a ruby library (as opposite to a Rails application)
and using plain Minitest and a minimal Rakefile

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

3 participants