Till now I am used to use the Scott Hanselman's Watir controller for NUnit just to integrate results of Ruby Test::Unit tests to CruiseControl.NET. It does good with NUnit results. So if we can run Ruby tests with NUnit, we have nothing more to do.
However, it would be good too to do without intermediate unit-testing code, if only Test::Unit runners could store there result in form of some common XML. And now it is done with use of Alexey Verkhovsky's Test::Unit::Reporter.
This is how the test-running Ruby script can look now:
# This part is all of old code to run tests.
# (It just picks all test cases from a directory — they start with "tc_")
require 'test/unit'
Dir['tc_*.rb'].each { |testCase| require testCase }
# This is the new part to replace autorunner.rb which would start otherwise.
# It should save the resulting XML to a directory named "TestResults".
require 'XMLRunner'
XMLRunner::report_to 'TestResults'
My XMLRunner module now has just this code inside. It is all that is needed to make the Test::Unit::Reporter produce results in XML form:
require 'test/unit/ui/console/testrunner'
require 'test/unit/ui/reporter'
require 'stringio'
module XMLRunner
def XMLRunner.report_to(dir)
ObjectSpace.each_object(Class) do |test|
Test::Unit::UI::Reporter.run(test.suite, dir, :xml) if
test < Test::Unit::TestCase
end
end
end
Thus, now we have XML files in JUnit result format. That is they can be directly used by any tool which works with JUnit test results.
And CruiseControl accepts them too! We just need to add a “merge” task in ccnet.config before the “xmllogger” task. Like this:
<merge>
<files>
<file>TestResults/TEST-TC_*.xml</file>
</files>
</merge>
and we already will get all ruby test failures in a build report:

As far as I understood, the Reporter class is not included in standard Test::Unit and Ruby installations. So it should be downloaded separately from rubyforge.org and then installed.
The other drawback is that CC.Net does not have reports for JUnit test details and test timings. However, it does have them for NUnit. Of course, including Ruby test results through NUnit test was not informative either. But now, having a proper test result XML in a build log we could display much more information. So I think of the xsl-stylesheet for JUnit details report as a thing wich is good to have. And I will appreciate it if someone already have written one :O)
Posted
Nov 29 2005, 03:04 PM
by
Yury Krasavin