C++ 谷歌测试:代码覆盖率
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2359344/
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
google-test: code coverage
提问by gruszczy
Is it possible to get code coverage done by tests using google test framework?
是否有可能通过使用谷歌测试框架的测试来完成代码覆盖率?
采纳答案by chalup
Yes, I've successfully used both free (gcov) and commercial (CTC++) tools. No special steps are needed, just follow the documentation.
是的,我已经成功地使用了免费 (gcov) 和商业 (CTC++) 工具。不需要特殊步骤,只需按照文档进行操作即可。
More details can be found in this blog http://googletesting.blogspot.dk/2014/07/measuring-coverage-at-google.html
可以在此博客中找到更多详细信息 http://googletesting.blogspot.dk/2014/07/measuring-coverage-at-google.html
回答by Jinay Patel
Yes, You can club your Gtest Based application with support of Gcov/lcov. refer the documentation of lcov http://ltp.sourceforge.net/coverage/lcov.php
是的,您可以在 Gcov/lcov 的支持下将您的基于 Gtest 的应用程序俱乐部化。参考 lcov 的文档http://ltp.sourceforge.net/coverage/lcov.php
there is one linux test project utility available which does your job very easy and is very self-interpretative.
有一个 linux 测试项目实用程序可用,它可以非常轻松地完成您的工作并且非常自我解释。
lcov
- a graphical GCOV front-end
lcov
- 图形化 GCOV 前端
Download from Ubuntu repo:
从 Ubuntu 仓库下载:
$ sudo apt-get install lcov
Use following commands in your build directory
$ lcov --directory ./build/ --capture --output-file ./code_coverage.info -rc lcov_branch_coverage=1
Run the Application
Generate HTML Report
$ genhtml code_coverage.info --branch-coverage --output-directory ./code_coverage_report/
在构建目录中使用以下命令
$ lcov --directory ./build/ --capture --output-file ./code_coverage.info -rc lcov_branch_coverage=1
运行应用程序
生成 HTML 报告
$ genhtml code_coverage.info --branch-coverage --output-directory ./code_coverage_report/
This will look something like - http://ltp.sourceforge.net/coverage/lcov/output/index.html
这看起来像 - http://ltp.sourceforge.net/coverage/lcov/output/index.html
回答by atlaste
(Only works on Windows)
(仅适用于 Windows)
It seems this question is still active, so here's an additional option. I've just tested Google Tests on our code coverage solution (yes, I'm the author), which works on Visual Studio. The project can be found at: https://github.com/atlaste/CPPCoverage
这个问题似乎仍然有效,所以这里有一个附加选项。我刚刚在我们的代码覆盖率解决方案上测试了 Google 测试(是的,我是作者),它适用于 Visual Studio。该项目可以在以下位置找到:https: //github.com/atlaste/CPPCoverage
Instructions: right-click project, run coverage. :-)
使用说明:右键项目,运行覆盖。:-)
If you prefer an XML output (for CI), you can call the coverage executable manually.
如果您更喜欢 XML 输出(用于 CI),您可以手动调用覆盖率可执行文件。