Hi All :
I just want share my testing with Ruby coverage code or Rcov. It is fun (for me, dont know for others) playing with Rcov report, i think it is like bugs tracking but i dont know other people called it or maybe it is like tool to coverage test your application codes.
First think you have to do is installing the gem :
gem install rcov
and then write simple code to run it as rake then save it in your_app/lib/tasks :
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"end
t.test_files = FileList["test/#{target}/*_test.rb"]
t.output_dir = File.dirname(__FILE__)+"/report_rcov/#{target}"
t.verbose = true
t.rcov_opts << '--rails --aggregate coverage.data'
end
task :coverage => "test:coverage:#{target}"
end
system(" \"C:/Program Files/Mozilla Firefox/firefox.exe\" " +
"file:///"+File.dirname(__FILE__)+"/report_rcov/unit/ index.html")
end
Absolutly i am using windows if you are using another OS not windows you could change the 4th line from bottom to :
system(open File.dirname(__FILE__)+"/report_rcov/unit/index.html" )
Open your shell or CMD then execute rake test:coverage or open rake -T
rake test:coverage# Aggregate code coverage for unit,...
rake test:coverage:clean# Delete aggregate coverage data.
rake test:coverage:clobber_functional # Remove rcov products for functional
rake test:coverage:clobber_integration # Remove rcov products for integration
rake test:coverage:clobber_unit# Remove rcov products for unit
rake test:coverage:functional# Analyze code coverage with tests ...
rake test:coverage:integration# Analyze code coverage with tests ...
rake test:coverage:unit# Analyze code coverage with tests ...
Here I attached sample report from rcov. I hope this written can be useful for you gentleman and ladies.
No Response to "Track Total Coverage of Your Test Unit Code with RCOV"
Post a Comment