4

I select a framework for unit tests in C++ The best (for me) solution is boost::test, because it goes in boost :)

But there is 1 problem - the framework must be able to generate XML output in JUnit format, but by default boost::test can generate either human-readable or own XML formats

  • (as I understand) I can write my own (custom) generator

So the question: does someone know the fastest way to make boost::test generate reports in JUnit format?

Alek86
  • 1,489
  • 3
  • 17
  • 26
  • 1
    JUnit doesn't have an XML output. Ant does, hudson/jenkins do. Which XML format are you talking about? – Matthew Farwell Dec 05 '11 at 23:58
  • Sorry, I'm not an expert in unit test reports. Looks like I need an Ant one. (http://junitpdfreport.sourceforge.net/managedcontent/PdfTranslation) – Alek86 Dec 06 '11 at 15:30

4 Answers4

2

Boost 1.62 provides built-in support for the JUnit format (see http://www.boost.org/doc/libs/1_62_0/libs/test/doc/html/boost_test/test_output/log_formats/log_junit_format.html).

Igor Akhmetov
  • 1,807
  • 13
  • 15
  • For those wondering how several loggers can be specified: https://www.boost.org/doc/libs/1_64_0/libs/test/doc/html/boost_test/utf_reference/rt_param_reference/logger.html – Elrond1337 Feb 07 '19 at 09:33
  • and this page says nothing about how to use it. As usual, boost documentation is the worst... – IceFire Jan 21 '22 at 14:51
  • Agree with IceFire. Someone asked a very specific question. It is always the worse when someone just points you to horrible documentation. Sanket C answer works great and they don't have to dig through documentation to find it. – ajpieri Jul 26 '23 at 17:49
1

Many a times the test could emit logs to stderr/stdout. If one needs only JUNIT format to log we can use the --logger option

./test --logger=JUNIT,all,reports.xml
Sanket C
  • 11
  • 1
0

You need to implement custom report formatter (implement interface results_reporter::format). Next you can create an instance of the formatter and register it inside your test module initialization function or global fixture.

Gennadiy Rozental
  • 1,905
  • 2
  • 13
  • 17
0

You can generate results of boost tests in a JUnit format by setting --log_format=JUNIT.

If you want to run a binary named test:

./test --log_level=all --log_format=JUNIT > reports.xml

This will generate a reports.xml file in JUnit format. The log_level=all is for loading all details of the tests.

Adrian Mole
  • 49,934
  • 160
  • 51
  • 83