33

I am new to using Google test framework for unit testing and am intending to generate an XML report of the tests or the command output as a report (I could just print it obviously). I have read up on Generate XML Report , but haven't been able to understand clearly on how to go about generating the report. Any help would be greatly appreciated.

Cheers.

DerKasper
  • 167
  • 2
  • 11
Neophile
  • 5,660
  • 14
  • 61
  • 107

4 Answers4

26

For Linux environments:

It's simple you just have to set the GTEST_OUTPUT environment variable like this: export GTEST_OUTPUT="xml:/home/user/src". or use the -gtest_output flag set the same way.

unludo
  • 4,912
  • 7
  • 47
  • 71
v01d
  • 1,457
  • 1
  • 11
  • 22
  • Do I set that in main? Any directions on where I could do so? – Neophile Nov 25 '11 at 11:45
  • Which operating system, IDE, compiler. – v01d Nov 25 '11 at 11:46
  • Windows XP Prof, Visual Studio 2005, C++ Programming. – Neophile Nov 25 '11 at 11:48
  • I have set the environment variable like the one you suggested. Where do you reckon I'd find the new xml report? – Neophile Nov 25 '11 at 12:05
  • in the line GTEST_OUTPUT="xml:/home/user/src" the path after the ":" is where you should put the path. Example if you want to put it in C:\report.xml set the variable like this: GTEST_OUTPUT="xml:c:\" – v01d Nov 25 '11 at 12:07
  • 2
    So, the syntax should be Variable: GTEST_OUTPUT, Value: export GTEST_OUTPUT="xml:C/MyXML" .. – Neophile Nov 25 '11 at 12:09
  • 1
    the Variable Name is GTEST_OUTPUT the Variable Value is "xml:c/MyXML" – v01d Nov 25 '11 at 12:14
  • ok so you have to test it the article on google says this is the name of the variable and the value should be the path where you want it to place the report. The report filename will be the same as this of the executable. – v01d Nov 25 '11 at 12:22
  • somehow it doesn't recognize "xml". – Neophile Nov 25 '11 at 12:32
  • I think this is some problem with your google test framework installation or configuration. I think you should read the manual again and chekc if you have configured visual studio for proper use of the framework. – v01d Nov 25 '11 at 12:35
  • Hmmm, thanks I'll give it a go myself. Cheers for your help anyways :) – Neophile Nov 25 '11 at 12:42
  • By the way, is there a way to print that command line output instead? – Neophile Nov 25 '11 at 12:49
  • Not sure will check but maybe tomorrow. – v01d Nov 25 '11 at 13:11
  • `--gtest_output` – hojin Sep 14 '22 at 05:02
15

I have referred to v01d's solution and just made a complete and properly framed answer for anyone else who might come across the same question.

Setting the Environment Variable:

  1. Goto MyComputer, right click and click on Properties.
  2. Click on the Advanced Tab, and click on Environment Variables.
  3. Click to Add a new variable and set the properties in the following way:

    • Variable: GTEST_OUTPUT

    • Value: xml:\home\user\XML_Report.xml

Restart your MSVC++ and run your program again. You should be able to find your XML Report in the corresponding folder as mentioned in the 'Value' property specified by you. Furthermore, you can even convert the xml report with the help of Microsoft Access into a particular choice of format you want. Just a simple tutorial/example of this is given here: XML Conversion.

Hope this helps!

Neophile
  • 5,660
  • 14
  • 61
  • 107
  • 1
    Can I have multiple GTest XML reports appended to the same XML file, instead of each GTest outputting to a new XML file (or overwriting a previous XML file) ? – nirvanaswap Jul 01 '16 at 00:20
  • 1
    This solution seems impractical if you have more projects to test (they write to the same file). You'd better use command line arguments as in '@akib khan' answer. – Fil May 03 '20 at 21:17
14

Apart from method suggested by @The Newbie you can also generate XML report by setting flag --gtest_output="xml:\home\user\XML_Report.xml" in command line.If you are using Microsoft Visual studio, then you can add in command arguments flag --gtest_output="xml:\home\user\XML_Report.xml"

Setting the command arguments flag :

  1. Right click on project and go to properties.
  2. Go to Configuration Properties->Debugging.
  3. In Command Arguments add --gtest_output="xml:\home\user\XML_Report.xml"
akib khan
  • 451
  • 4
  • 9
7

Googletest does not generate JUnit compatible XML file, in such scenarios you need to convert the generated XML to JUnit XML format.

Reported Issue

Workaround Solution

Community
  • 1
  • 1
Gayan Pathirage
  • 1,979
  • 1
  • 24
  • 21