3

I can run a Catch executable with -o junit --output catch_results.xml to generate an xml report.

Is there some way to both generate an xml report, and also have the console output?

Daniel Paczuski Bak
  • 3,720
  • 8
  • 32
  • 78
  • 3
    If you are using a unix-like environment, you could output to stdout and use `tee` to fork the output to a file. –  May 21 '19 at 18:44
  • On Windows, [Powershell can do the same thing](https://stackoverflow.com/a/20854632/201787): `powershell ".\myTestExe -o junit | tee catch_results.xml"` – metal May 21 '19 at 18:56
  • When I tried this, the file catch_results.xml contained only "-ojunit". – Scott Hutchinson Sep 04 '19 at 21:21
  • Your arguments seems to be incorrect, it should be `--reporter junit --out catch_results.xml` – Synck Oct 08 '19 at 11:18

3 Answers3

2

Assuming you are asking for having a JUnit output in a file and the standard console reporter at stdout, there is no way to do that.

Catch2 used to support multiple reporters, but there was no support for having them write their output to separate files/outputs, which meant that the feature was unusable and was removed until some point in the future.

Quentin
  • 62,093
  • 7
  • 131
  • 191
Xarn
  • 3,460
  • 1
  • 21
  • 43
2

You can implement your own Listener.
A Listener can implement 'event handlers' for certain events (test suite start/end, test case start/end, ...). In those event handlers you can output to the console (use printf instead of cout as cout can be intercepted by the test runner).

And, most importantly, your Listener can run in combination with a reporter.

https://github.com/catchorg/Catch2/blob/master/docs/event-listeners.md

Synck
  • 2,727
  • 22
  • 20
1

If you are able to move to C++14 and update Catch to v3.x then it is quite easy.

Just call

myTest.exe --reporter JUnit::out=result-junit.xml --reporter console::out=-::colour-mode=ansi

This will print the end result to the command line, and the JUnit result to result-junit.xml

For more information about the reporters go to Catch2 reporters .
Moving from Catch2 to Catch3 is also not so painful. Migrating for v2 to v3. Side note: you can still use the one header-ish version, see migration option 1.

zerocukor287
  • 555
  • 2
  • 8
  • 23