CMake CTest output to JUnit XML
Asked Answered
B

2

7

Is there a way to report the results in a JUnit XML format with CTest? I have found the the --output-junit comand-line switch but running ctest --output-junit testRes.xml does not create output file...

Betroth answered 14/9, 2021 at 10:19 Comment(0)
P
10

ctest --output-junit testRes.xml doas not create output file...

This is relatively new feature, You just need to update Your CMake / CTest to v.3.21.4 or higher (ref. https://cmake.org/cmake/help/v3.21/manual/ctest.1.html)

Proficiency answered 19/1, 2022 at 17:0 Comment(3)
I got the same problem with ctest version 3.25.1. I'm investigating now. I'll post something here if I found a solution.Alida
I understood/solved the issue. Running ctest --output-junit build/ctest-results.xml --test-dir build will create a file ./build/build/ctest-results.xml, that is, the output file specified with the option --output-junit is relative to the directory specified with --test-dir, not relative to the current directory.Alida
Ugh it seems like you are right. And ctest very helpfully does not give any kind of unknown argument error - it just ignores unknown arguments. That's the kind of shoddy engineering that costs people (i.e. me) hours of their lives. :-/Knowable
S
0

Same issue. I don't examine it deeply. But I guess there is convenient workaround: ask CMake to call test executable with native option aimed to produce JUnit report by itself.

This approach allows you to get as detailed JUnit report as possible. Such report will contain individual log records of each test case being inside called executable file, not whole executable at once. I proceed from the assumption that in general case CMake cann't parse stdout of every test framework at any verbosity level to collect anought data to produce pretty JUnit report.

Moving on to the example, let's say we are dealing with a unit test based on Boost.Test. Then just add it to a CMake project by the following way

add_test(
    NAME ${test_name}
    COMMAND ${boost_test_executable_file} --logger=JUNIT,message,${path_to_junit_log}
)

and get a JUnit report.

Subastral answered 22/12, 2021 at 23:11 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.