8

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...

2 Answers 2

11

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)

Sign up to request clarification or add additional context in comments.

3 Comments

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.
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.
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. :-/
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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.