4

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

Hallootto1100
  • 61
  • 2
  • 7

2 Answers2

7

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)

Roman
  • 91
  • 1
  • 2
  • 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. – Kevin Dec 20 '22 at 15:01
  • 2
    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. – Kevin Dec 20 '22 at 15:13
  • 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. :-/ – Timmmm Apr 05 '23 at 12:21
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.

Nikita
  • 191
  • 1
  • 4