simplecov-ruby /simplecov

Code coverage for Ruby with a powerful configuration library and automatic merging of coverage across test suites

★ 4,929⑂ 584👁 53⑃ 687● 652▤ 40
RubyMITCreated 2010-08-15
下载:v1.3.2v1.3.2 ↓1.3.22026-09-30
-1
日增长
4,929
stars
584
forks
53
watchers
687
prs
652
issues
40
releases

README

SimpleCov  ![Build Status][ci]     
=========

Code coverage for Ruby

[ci]: https://github.com/simplecov-ruby/simplecov/actions?query=workflow%3Astable

SimpleCov is a code coverage analysis tool for Ruby. It uses [Ruby's built-in
Coverage][Coverage] library to gather coverage data, but makes processing the
results much easier by providing a clean API to filter, group, merge, format,
and display them. You can get a full coverage setup running in a couple of
lines of code.

[Coverage]: https://docs.ruby-lang.org/en/master/Coverage.html

SimpleCov tracks covered Ruby code.

In most cases you'll want overall coverage results spanning all of your tests
(unit, integration, etc.). SimpleCov handles this automatically by caching and
merging results as it generates reports, so a report reflects coverage across
your whole test suite and gives you a truer picture of your blank spots.

SimpleCov bundles two formatters: the default HTML formatter (which renders the
browsable report) and a JSON formatter. Both were once separate gems
(simplecov-html and simplecov_json_formatter) but are now built into
SimpleCov and configured automatically when you launch it. A wide variety of
alternate formatters are distributed as gems.

 Getting started

1. Add SimpleCov to your Gemfile and bundle install:

    ruby
    gem 'simplecov', require: false, group: :test
    

2. Load and launch SimpleCov at the very top of your test helper, whether
   that's test/test_helper.rb, spec/spec_helper.rb, rails_helper.rb, or
   Cucumber's features/support/env.rb. SimpleCov doesn't care which framework
   you run. It watches what code executes and reports on it, so the same two
   lines work everywhere:

    ruby
    require 'simplecov'
    SimpleCov.start

     Previous content of test helper now starts here
    

    Important: SimpleCov.start must run before any of your
    application code is required. Otherwise SimpleCov (and the underlying
    Coverage library) can't track those files. This bites hardest with tools
    that keep your app loaded between runs, like Spring. See the
    Spring section.

   SimpleCov must run in the process you want to analyze. When you test a
   server process (e.g. a JSON API) from a separate test process (e.g. via
   Selenium) and want to see all the code the rails server executes, not just
   the code in your test files, require SimpleCov in the server process. For
   Rails, add this near the top of bin/rails, below the shebang and after
   config/boot is required:

    ruby
    if ENV['RAILS_ENV'] == 'test'
      require 'simplecov'
      SimpleCov.start 'rails'
    end
    

3. Run your full test suite to see your application's coverage.

4. Open the HTML report in your default browser:

    sh
    simplecov open
    

   (The bundled simplecov CLI picks the right opener for your platform:
   open on macOS, xdg-open on Linux/BSD, start on Windows. Pass
   --report PATH to open a non-default location. See the
   command-line interface for the f

Latest release

v1.3.2 v1.3.2 2026-09-30
Bugfixes
 The HTML report is generated again on Rails 8.1.4 when a parallelize_teardown hook calls SimpleCov.result. Rails 8.1.4 runs those hooks in the parent process as well as in each worker, and collecting the result there stops Coverage, which the exit handler took as a sign that nothing was left to report. The exit handler now formats a result that was already collected. See https://github.com/simplecov-ruby/simplecov/issues/1308.

Snapshot: 2026-11-16T09:23:14Z · Data license Apache-2.0 · JSON