Set up continuous build server to include acceptance tests using Watir

By mark

Acceptance tests integrated into the continuous build server provides team members constant feedback, its benefits is quite obvious. Here I show you how to include web acceptance tests (using Watir) in CruiseControl server for a typical Java/J2EE project.

Prerequisite:

  • CruiseControl  installed and configured properly.
  • Ruby and Watir/rWebUnit installed, easiest way is to install PRoR.

1.  Create a Rakefile in your acceptance test folder (in our example, test/acceptance)

    require 'rubygems'
gem 'ci_reporter'
gem 'rspec'
require "rexml/document"
require "spec/rake/spectask"
require 'ci/reporter/rake/rspec' # use this if you're using RSpec
 
task :default => ["test:acceptance"]
Spec::Rake::SpecTask.new("quick") do |t|
    t.spec_files = FileList[
       "login_spec.rb",
       "payment_spec.rb",
    ]
    t.warning = false
end
task "test:acceptance" => "ci:setup:rspec" do
  Rake::Task["quick"].invoke
end
  

2. Test it out by running tests from command line

C:\wenji>rake test:acceptance   
(in C:/wenji) 
rm -rf spec/reports   
.   
.  
.    
Finished in 98.547 seconds

3. Add the acceptance test target in your Ant build.xml

    <property name="test.acceptance.dir" value="test/acceptance"/>
 
 <!-- Run acceptance tests from Ant script -->
 <target name="test.acceptance">
     <exec executable="cmd" dir="${test.acceptance.dir}" resultproperty="test.acceptance.result">
         <arg value="/c"/>
         <arg value="rake"/>
         <arg value="test:acceptance"/>
     </exec>
     <echo message="acceptance result: ${test.acceptance.result}"/>
     <antcall target="test.acceptance.report"/>     
     <fail message="rWebUnit tests failed" unless="test.acceptance.result"/>
 </target>

  <!-- The html report are under test/acceptance/spec/reports_html -->
  <target name="test.acceptance.report">
        <delete dir="${test.acceptance.dir}/spec/reports_html"/>
        <mkdir dir="${test.acceptance.dir}/spec/reports_html"/>
        <mkdir dir="${test.acceptance.dir}/spec/reports"/>
        <junitreport todir="${test.acceptance.dir}/spec/reports_html">
            <fileset dir="${test.acceptance.dir}/spec/reports">
                <include name="SPEC-*.xml"/>
            </fileset>
            <report format="frames" todir="${test.acceptance.dir}/spec/reports_html"/>
        </junitreport>
  </target>
  

 Test it out

    ant -f build.xml test.acceptance
  

4. Add this new acceptance target to main build target triggered by CC

    <target name="go" depends="compile, coverage.instrument, test.unit, deploy, test.acceptance" 
  description="Quick build as triggered by CruiseControl Server - build, deploy, and test" > </target>
  

5. You will see acceptance tests running for next CruiseControl build, to view acceptance test report (called Artifact in CC), edit CC project file under publishers

    <artifactspublisher 
  subdirectory="acceptance_test_report" 
  dir="${trunk}/test/acceptance/spec/reports_html" 
  dest="artifacts/${project.name}">
</artifactspublisher>