Ruby Test Integration With CruiseControl.net

Please use the thread Integrating Ruby On Rails Unit Tests in CruiseControl.net for posting comments about this procedure.

In order to integrate your ruby on rails unit tests into your CruiseControl build process so you can see the test results in the webdashboard, you must peform the following tasks in order:

Installing Test-Report:
  • Download and extract the contents of the test-report-0.3.0.zip (looks like the rubyforge project vaporized so I uploaded a copy that I had) Version 0.3.0 distribution.
  • Open the folder where you saved the test-report code.
  • Modify the /lib/test/unit/ui/reporter.rb, and add the following snippet just beneath the other 'require' declarations.
require 'test/unit/ui/console/testrunner'
  • Open a command prompt in the test-report root directory.
  • Execute > ruby.exe setup.rb config
    • This command configures the test-report addin to work with your installation of Ruby.
  • Execute > ruby.exe setup.rb install
    • This command adds the test-report files to your ruby library.

Setting up WebDashboard:
  • Download rubyunittests.xsl and save it to your CruiseControl.NET/webdashboard/xsl/ folder.
  • Now you must change your CruiseControl.NET/webdashboard/dashboard.config file so it will show a new RUnit Details report in the Dashboard's left navigation.
  • Open the dashboard.config file and modify it by adding your own "xsl report build plugin".
<!-- Example From File: /CruiseControl.NET/webdashboard/dashboard.config -->
<dashboard>
    <plugins>
        <buildPlugins>
            <!-- This is where you insert the following line -->
            <xslReportBuildPlugin description="RUnit Details" actionName="RunitBuildReport" 
                xslFileName="xsl\rubyunittests.xsl />
        </buildPlugins>
    </plugins>
</dashboard>


Configuring Your tests.rb File:
  • Download tests.rb and save it to the root of your Ruby On Rails application.
  • The tests.rb sample file assumes a pattern of /tests/unit//*_test.rb, you will need to change this pattern or add your own methods for adding functional tests or other tests directories you wish to generate results for.
  • Don't forget to modify the tests.rb file for your specific database configuration, specifically the createDatabase method. This example file assumes SQL Server 2005.
  • Note: To configure different databases, look at the Ruby Active Record source code located in your c:/ruby/lib/ruby/gems/1.8/gems/activerecord-x.x.x/lib/activerecord/connectionadapters/. Specifically, look at the adapter_name property for the connection adapter your application requires.

Setting up Your Build Script:
  • Add a build task in your build.myproject.xml MSBuild script file as show below, this will execute the unit tests.
<!-- Run Ruby Unit Tests -->
<Target Name="run-tests">
    <Exec ContinueOnError="false" Command="c:\ruby\bin\ruby.exe tests.rb"
        WorkingDirectory="c:\projects\myrailsapp\">
	<Output TaskParameter="ExitCode" ItemName="ExitCodes"/>
    </Exec>
    <Error Text="One or more Unit Tests failed." Condition="'%(ExitCodes.Identity)'>0"/>
</Target>
  • In the build script for your project, add a file merge publisher. This will merge your unit test output details into the cruise control build log for your project.
  • Note: You can change the name of the output results xml file by changing the name of your TestSuite class's constructor where it calls the base class's initialize('MyRailsApp') argument, located in tests.rb.
<project>
     <!-- Some Build Script Settings -->
     <publishers>
         <merge>
	     <files>
                 <file>C:\Projects\MyRailsApp\TestResults\TEST-MyRailsApp.xml</file>
             </files>
         </merge>
     </publishers>
     <!-- Some Other Build Script Settings -->
</project>


Files:
tests.rb
runit.xsl
test-report-0.3.0.zip (added local copy because rubyforge site is gone!)

Links:
Test-Report Version 0.3.0 - http://test-report.rubyforge.org (site is down or does not exist anymore)
Throughworks CruiseControl.Net - http://cruisecontrol.confluence.net

Last edited Mar 15, 2007 at 9:37 PM by bheinz, version 10

Comments

No comments yet.