生成 Google C++单元测试 XML 报告
我刚开始使用 Google 测试框架进行单元测试,并且打算生成测试的 XML 报告或命令输出作为报告(我可以直接打印它)。我已阅读生成 XML 报告 < /a>,但无法清楚地了解如何生成报告。任何帮助将不胜感激。
干杯。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
对于
Linux
环境:很简单,您只需设置
GTEST_OUTPUT
环境变量,如下所示:export GTEST_OUTPUT="xml:/home/user/src".或使用以相同方式设置的
--gtest_output
标志。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.我参考了 v01d 的解决方案,并为可能遇到相同问题的其他人提供了完整且正确的答案。
设置环境变量:
单击添加新变量并按以下方式设置属性:
变量: GTEST_OUTPUT
值: xml:\home\user\XML_Report.xml
重新启动 MSVC++ 并运行程序 再次。您应该能够在您指定的“Value”属性中提到的相应文件夹中找到您的 XML 报告。此外,您甚至可以借助 Microsoft Access 将 xml 报告转换为您想要的特定格式。这里仅给出一个简单的教程/示例: XML 转换。
希望这有帮助!
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:
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!
除了@The Newbie 建议的方法之外,您还可以通过在命令行中设置标志 --gtest_output="xml:\home\user\XML_Report.xml" 来生成 XML 报告。如果您使用的是 Microsoft Visual studio,然后您可以添加命令参数标志 --gtest_output="xml:\home\user\XML_Report.xml"
设置命令参数标志:
属性->调试。
--gtest_output="xml:\home\user\XML_Report.xml"
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 :
Properties->Debugging.
--gtest_output="xml:\home\user\XML_Report.xml"
Googletest 不会生成 JUnit 兼容的 XML 文件,在这种情况下您需要将生成的 XML 转换为 JUnit XML 格式。
报告的问题
解决方案
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