生成 Google C++ 单元测试 XML 报告
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/8268584/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Generate Google C++ Unit Test XML Report
提问by Neophile
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.
我是使用 Google 测试框架进行单元测试的新手,并且打算生成测试的 XML 报告或命令输出作为报告(我可以很明显地打印出来)。我已经阅读了Generate XML Report,但无法清楚地了解如何生成报告。任何帮助将不胜感激。
Cheers.
干杯。
采纳答案by Neophile
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.
我已经提到了 v01d 的解决方案,并且刚刚为可能遇到相同问题的任何其他人提供了一个完整且框架正确的答案。
Setting the Environment Variable:
设置环境变量:
- Goto MyComputer, right click and click on Properties.
- Click on the AdvancedTab, and click on Environment Variables.
Click to Add a new variable and set the properties in the following way:
Variable:GTEST_OUTPUT
Value:xml:\home\user\XML_Report.xml
- 转到MyComputer,右键单击并单击“属性”。
- 单击高级选项卡,然后单击环境变量。
单击以添加新变量并按以下方式设置属性:
变量:GTEST_OUTPUT
值: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.
重新启动您的 MSVC++ 并再次运行您的程序。您应该能够在您指定的“值”属性中提到的相应文件夹中找到您的 XML 报告。此外,您甚至可以在 Microsoft Access 的帮助下将 xml 报告转换为您想要的特定格式选择。这里给出了一个简单的教程/示例:XML 转换。
Hope this helps!
希望这可以帮助!
回答by v01d
For Linux environments:
对于 Linux 环境:
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.
很简单,您只需像这样设置 GTEST_OUTPUT 环境变量:export GTEST_OUTPUT="xml:/home/user/src"。或使用 -gtest_output 标志设置相同的方式。
回答by akib khan
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"
除了@The Newbie 建议的方法外,您还可以通过在命令行中设置标志--gtest_output="xml:\home\user\XML_Report.xml"来生成 XML 报告。如果您使用的是 Microsoft Visual Studio,则可以添加命令参数标志--gtest_output="xml:\home\user\XML_Report.xml"
Setting the command arguments flag :
设置命令参数标志:
- Right click on project and go to properties.
- Go to Configuration Properties->Debugging.
- In Command Arguments add --gtest_output="xml:\home\user\XML_Report.xml"
- 右键单击项目并转到属性。
- 转到配置属性->调试。
- 在命令参数中添加 --gtest_output="xml:\home\user\XML_Report.xml"
回答by Gayan Pathirage
Googletest does not generate JUnit compatible XML file, in such scenarios you need to convert the generated XML to JUnit XML format.
Googletest 不会生成 JUnit 兼容的 XML 文件,在这种情况下您需要将生成的 XML 转换为 JUnit XML 格式。

