eigenclass logo
MAIN  Index  Search  Changes  PageRank  Login

rcov 0.7.0: code coverage and callsite/defsite data aggregation across multiple runs

rcov 0.7.0 can aggregate code coverage and defsite/callsite data collected in successive runs. This is useful when you want to obtain a global coverage rate but your tests are split into several parts, for instance units, functionals and integration, as happens in Rails.

Here's how you'd define coverage tasks for unit, functional and integration tests under the test:coverage namespace, as well as a test:coverage task that runs them all and yields an aggregate coverage rate:

require 'rcov/rcovtask'

namespace :test do 
  namespace :coverage do
    desc "Delete aggregate coverage data."
    task(:clean) { rm_f "coverage.data" }
  end
  desc 'Aggregate code coverage for unit, functional and integration tests'
  task :coverage => "test:coverage:clean"
  %w[unit functional integration].each do |target|
    namespace :coverage do
      Rcov::RcovTask.new(target) do |t|
        t.libs << "test"
        t.test_files = FileList["test/#{target}/*_test.rb"]
        t.output_dir = "test/coverage/#{target}"
        t.verbose = true
        t.rcov_opts << '--rails --aggregate coverage.data'
      end
    end
    task :coverage => "test:coverage:#{target}"
  end
end

All you have to do to combine data from multiple runs is to add

 --aggregate FILE

so that the data from previous runs saved in FILE is loaded (if FILE doesn't exist then history will be empty), merged with the newer information and stored back into FILE:

rm coverage.data
rcov --aggregate coverage.data test/unit/*.rb
rcov --aggregate coverage.data test/integration/*.rb

coverage.data will hold quite a lot of information: all the Ruby code that was executed, execution counts and coverage data for all files.

Download

The tarball with the latest sources is available here. You can also get it via rubyforge, or install with gem install rcov (the packages haven't been propagated to the mirrors as of 9:34 UTC, allow some more time).

User-visible changes since 0.6.0 (2006-06-12)

Features

  • coverage/callsite data from multiple runs can be aggregated (--aggregate)

Bugfixes

  • the SCRIPT_LINES__ workaround works better
  • fixed silly bug in coverage data acquisition (line after the correct one marked in some situations)
  • avoid problems with repeated path separators in default ignore list, based on rbconfig's data

Thanks

Thomas Leitner:
  • reported that the SCRIPT_LINES__ workaround did not always work
Assaph Mehr:
  • beta-tested 0.7.0 and found a bug in --aggregate (missing files)
Ryan Kinderman:
  • suggested that -Ipath be passed to ruby instead of rcov in RcovTasks

Last modified:2006/08/04 03:00:00
Keyword(s):[blog] [ruby] [frontpage] [rcov] [0.7.0] [release] [code] [coverage]
References:[rcov: code coverage for Ruby]