Since I needed to parse the results of some CUnit tests in Hudson in a recent project, I came up with the following transformation which I apply to the cunit xml result file.

Hudson can then evaluate the results as if they were generated by JUnit. The same approach is basically used in the CppUnit Plugin for Hudson - which is where I got the idea.

Since I’m too lazy at the moment to write my own plugin for Hudson, I figured running xsltproc after running my tests will be good enough:

xsltproc-win32xsltproc.exe --stringparam suitename testall -o testall_results.xml cunit-to-junit.xsl cunit_testall-Results.xml

To make CUnit produce XML results, you have to do something like this:

CU_set_output_filename( "cunit_testall" );
CU_list_tests_to_file();
CU_automated_run_tests();

You can download the cunit-to-junit.xsl here.

The file with syntax highlighting follows. Listing removed because the highlighting broke the XSLT syntax. Use the downloadable file instead! Please note that it is not yet complete as I haven’t really tested it with all possible results cunit can produce. That I will do at a later time. Maybe togehter with a Hudson Plugin.

EDIT: The xslt transform is now also available on BitBucket. If you have made modifications feel free to contribute them there: http://www.van-porten.de/2011/09/cunit-to-junit-transform-now-on-bitbucket/

EDIT: Since you asked, License information follows:

Copyright (c) 2011 Oliver van Porten

Permission is hereby granted, free of charge, to any person
obtaining a copy of this software and associated documentation files
(the "Software"), to deal in the Software without restriction,
including without limitation the rights to use, copy, modify, merge,
publish, distribute, sublicense, and/or sell copies of the Software,
and to permit persons to whom the Software is furnished to do so,
subject to the following conditions:

The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

Leave a comment