Custom rake task for Hudson

Custom rake task for Hudson

When I tried to setup up a Hudson job for continuously running our unit and Cucumber tests, I came across several difficulties (e.g. producing proper output which is readable by Hudson). These ultimately lead to writing a custom Rake task for properly setting up and running the tests.

The task requires the ci_reporter plugin to generate JUnit output from the unit tests (Cucumber supports this out of the box). Additionally, everything required for gathering code coverage data is included as well.

Put this into lib/tasks/hudson.rb:

require 'ci/reporter/rake/test_unit'
require 'rcov/rcovtask'

namespace :hudson do
 def report_path
   "hudson/reports"
 end

 task :all => [:report_setup] do
   Rake::Task['hudson:test'].invoke
   Rake::Task['hudson:coverage'].invoke
   Rake::Task['hudson:cucumber'].invoke
 end

 task :test => ['ci:setup:testunit'] do
   Rake::Task['test'].invoke
 end

 task :coverage
 %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 = "#{report_path}/rcov"
       t.verbose = true
       t.rcov_opts << '--rails --aggregate coverage.data --no-html'
     end
   end
   task :coverage => "hudson:coverage:#{target}"
 end

 Cucumber::Rake::Task.new('cucumber') do |t|
   t.cucumber_opts = %{--format junit --out #{report_path}/features}
   t.rcov = true
   t.rcov_opts = %w{--rails --aggregate coverage.data --exclude osx\/objc,gems\/,spec\/,\.bundler\/,features\/}
   t.rcov_opts << %[-o "#{report_path}/rcov"]
 end

 task :report_setup do
   rm_rf 'coverage.data'
   rm_rf report_path

   ENV['CI_REPORTS'] = %{#{report_path}/tests}
 end

end

Now configure the following build stepts in Hudson:

  1. Execute shell command: bundle install
  2. Execute Rake: db:schema:load RAILS_ENV=test
  3. Execute Rake: hudson:all RAILS_ENV=test

When configuring the Rcov post build step, use this directory: hudson/reports/rcov. Now Hudson should run all your Rails tests as well as the Cucumber tests and gather the coverage data.

Über den Autor

Bewertet mit durchschnittlich
4.5
Sternen von
69
Lesern.

fortytools by zvoove für Ihre Branche

No items found.

Jetzt 30 Tage kostenlos und unverbindlich testen

Alle Funktionen stehen uneingeschränkt zur Verfügung. Keine Software-Installation, keine Probleme mit Updates. Einfach via Browser Einloggen und fertig. Von jedem internetfähigen Gerät.
Heute kostenlos testen!
Nutzerbewertung: 4,8 von 5 Sternen