CUnit Tests in Hudson
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-win32\xsltproc.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. 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.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 | <?xml version="1.0" encoding="UTF-8"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:output method="xml" indent="yes" /> <xsl:param name="suitename" /> <xsl:variable name="cunitCount" select="count(//CUNIT_RUN_TEST_RECORD)"/> <xsl:variable name="cunitFailureCount" select="count(//CUNIT_RUN_TEST_FAILURE)"/> <xsl:template match="/"> <testsuites> <xsl:attribute name="errors">0</xsl:attribute> <xsl:attribute name="failures"> <xsl:value-of select="$cunitFailureCount"/> </xsl:attribute> <xsl:attribute name="tests"> <xsl:value-of select="$cunitCount"/> </xsl:attribute> <xsl:attribute name="name"> <xsl:value-of select="$suitename" /> </xsl:attribute> <xsl:apply-templates /> </testsuites> </xsl:template> <xsl:template match="/CUNIT_TEST_RUN_REPORT/CUNIT_RESULT_LISTING"> <xsl:for-each select="CUNIT_RUN_SUITE/CUNIT_RUN_SUITE_SUCCESS"> <xsl:variable name="localCunitFailureCount" select="count(CUNIT_RUN_TEST_RECORD/CUNIT_RUN_TEST_FAILURE)"/> <xsl:variable name="localCunitCount" select="count(CUNIT_RUN_TEST_RECORD)"/> <xsl:variable name="sn" select="normalize-space(SUITE_NAME/text())"/> <testsuite> <xsl:attribute name="errors">0</xsl:attribute> <xsl:attribute name="failures"> <xsl:value-of select="$localCunitFailureCount"/> </xsl:attribute> <xsl:attribute name="tests"> <xsl:value-of select="$localCunitCount"/> </xsl:attribute> <xsl:attribute name="name"> <xsl:value-of select="$sn"/> </xsl:attribute> <xsl:apply-templates select="CUNIT_RUN_TEST_RECORD" /> </testsuite> </xsl:for-each> </xsl:template> <xsl:template match="CUNIT_RUN_TEST_RECORD"> <xsl:apply-templates select="CUNIT_RUN_TEST_SUCCESS" /> <xsl:apply-templates select="CUNIT_RUN_TEST_FAILURE" /> </xsl:template> <xsl:template match="CUNIT_RUN_TEST_SUCCESS"> <testcase> <xsl:attribute name="classname"> <xsl:value-of select="substring-before(substring-after(TEST_NAME,'test_'),'_')" /> </xsl:attribute> <xsl:attribute name="name"> <xsl:value-of select="normalize-space(TEST_NAME)" /> </xsl:attribute> <xsl:attribute name="time">0</xsl:attribute> </testcase> </xsl:template> <xsl:template match="CUNIT_RUN_TEST_FAILURE"> <testcase> <xsl:attribute name="classname"> <xsl:value-of select="substring-before(substring-after(TEST_NAME,'test_'),'_')" /> </xsl:attribute> <xsl:attribute name="name"> <xsl:value-of select="normalize-space(TEST_NAME)" /> </xsl:attribute> <xsl:attribute name="time">0</xsl:attribute> <failure> <xsl:attribute name="message"> <xsl:value-of select=" normalize-space(CONDITION)" /> </xsl:attribute> <xsl:attribute name="type">Failure</xsl:attribute> <xsl:value-of select="normalize-space(CONDITION)" /> File: <xsl:value-of select="normalize-space(FILE_NAME)" /> Line: <xsl:value-of select="normalize-space(LINE_NUMBER)" /> </failure> </testcase> </xsl:template> <xsl:template match="text()|@*" /> </xsl:stylesheet> |