MarkbCodes
MarkbCodes

Reputation: 21

Why does CTest output a junit xml in googletest format or why does Jenkins plugin XUnit think that it is?

I am building a jenkins pipeline job from scratch. Once the product is built, I run the unit tests on it via CTest. The XUnit Jenkins plugin requires a JUint xml file to report the tests on the build dashboard. I am having trouble with CTest's xml output.

The unit tests are googletest tests and are registered to CTest via the gtest_discover_tests(${TEST_PROJECT_NAME}) cmake command. Running the tests with ctest shows all the unit tests running properly and prints the output to the console - all as expected.
I want the output in an JUnit xml format to use in the XUnit Jenkins plugin, so I add this command to my pipeline script:

ctest arguments: '''
                 -T test
                 --no-compress-output
                 --output-junit ctestReport.xml
                 ''',

The ctestReport.xml file is generated and contains information about all the unit tests. Then I call xunit to process the tests for a report using the pipeline script command:

xunit (
            tools: [CTest(
            pattern: '**/ctestReport.xml',
            deleteOutputFiles: true,
            failIfNotNew: false,
            skipNoTestFiles: true,
            stopProcessingIfError: true
            )]
        )

However after the Jenkins job has completed, the XUnit test report shows only "No tests". However, if I modify the command to expect a googletest output:

xunit (
            tools: [GoogleTest(
            pattern: '**/ctestReport.xml',
            deleteOutputFiles: true,
            failIfNotNew: false,
            skipNoTestFiles: true,
            stopProcessingIfError: true
            )]
        )

Then XUnit correctly picks up all the tests and displays it on the panel etc.
If instead I use the googletest output, rather than the CTest output, then that also works with the modified xunit pipeline command.

I am using CMake version 3.29, googletest version (1.14.0), Jenkins v2.452.1 and XUint plugin v3.1.4 (All as up to date as possible)

Why does XUnit not pick up the test results when the xml is processed as a CTest report? Why does it pick them up when the xml output of CTest is treated as if output of googletest?

Upvotes: 1

Views: 236

Answers (0)

Related Questions