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.
Thank you for this great article! I will use hudson also for my c projects and your xsl is very helpful to do this.
My question is: develop you currently on the xslt-file or is your plugin ready?
I'm currently neither working on the xslt file nor on a plugin. My priorities at work shifted somewhat and I currently do not find the time nor the motivation to work on this in my spare time.
Thank you for this! It was very useful. Only a couple of changes were required for us. I had a question for you but I could not find an email address to contact you at:
I made some changes to your stylesheet (reference to this article is, of course, included), and would like to use it on our company's jenkins server for some cunit tests. Would that be ok with you?
Of course, that's fine. Go ahead and use it.
@Sagar: I'm evaluating the use of jenkins in my project in the company. We're using CUnit as well and as I haven't found any plugin for it. So, could you send me your version as it should be closer to what we need…? Thanks!
Great work! I'd be very happy if I could copy/redistribute cunit-to-junit.xsl (i.e. include in a test suite for my project.) If I could, under what condition?
Consider it MIT licensed.
I've just put the LICENSE information on the BitBucket page:
https://bitbucket.org/mcdeck/cunit-to-junit/src/t…
I'll also add that information to this page in a second.
I got it. Thanks a lot!