Skip to content

Instantly share code, notes, and snippets.

@jcasimir
Last active March 1, 2024 08:01
Show Gist options
  • Star 16 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • Save jcasimir/3c687bd5db16a73b4cf3 to your computer and use it in GitHub Desktop.
Save jcasimir/3c687bd5db16a73b4cf3 to your computer and use it in GitHub Desktop.
Running all MiniTest Tests with SimpleCov
test/coverage/
require 'rake/testtask'
Rake::TestTask.new do |t|
t.pattern = "test/**/*_test.rb" # This expects your tests to be inside a test subfolder
end # and end with '_test.rb`
# Run all your test files from the terminal with "rake test"
require 'simplecov' # These two lines must go first
SimpleCov.start
require 'minitest/autorun' # Sets up minitest
# You could require other shared gems here, too
class YourClass # Nothing special/unusual here
end
require_relative 'test_helper' # require test_helper first
require_relative 'your_class' # require whatever class(es) you're testing
class YourClassTest < Minitest::Test
def test_it_does_stuff # write your tests like normal
assert_equal 100, 100
end
end
@simondobson
Copy link

THANK YOU 💙

@vysogot
Copy link

vysogot commented Jan 7, 2021

Thanks for require 'simplecov' # These two lines must go first

@robertguturing
Copy link

OMG THANK YOU

@AlexcastroDev
Copy link

Thank youu

@artur-intech
Copy link

artur-intech commented Mar 1, 2024

Don't forget to filter out test files themselves:

SimpleCov.start do
  add_filter '/test/'
end

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment