46

是否可以通过使用谷歌测试框架的测试来完成代码覆盖率?

4

3 回答 3

32

是的,我已成功使用免费 (gcov) 和商业 (CTC++) 工具。无需特殊步骤,只需按照文档操作即可。

可以在此博客 http://googletesting.blogspot.dk/2014/07/measuring-coverage-at-google.html中找到更多详细信息

于 2010-03-01T22:18:18.157 回答
17

是的,您可以在 Gcov/lcov 的支持下加入您的基于 Gtest 的应用程序。请参阅 lcov http://ltp.sourceforge.net/coverage/lcov.php的文档

有一个可用的 linux 测试项目实用程序,它可以让您的工作非常轻松,并且非常具有自我解释性。

lcov- 图形 GCOV 前端

从 Ubuntu 存储库下载:

$ sudo apt-get install lcov
  1. 在构建目录中使用以下命令

    $ lcov --directory ./build/ --capture --output-file ./code_coverage.info -rc lcov_branch_coverage=1
    
  2. 运行应用程序

  3. 生成 HTML 报告

    $ genhtml code_coverage.info --branch-coverage --output-directory ./code_coverage_report/
    

这看起来像 - http://ltp.sourceforge.net/coverage/lcov/output/index.html

于 2016-05-02T10:46:40.227 回答
13

(仅适用于 Windows)

看来这个问题仍然存在,所以这里有一个额外的选项。我刚刚在我们的代码覆盖解决方案(是的,我是作者)上测试了 Google 测试,它适用于 Visual Studio。该项目可以在以下位置找到:https ://github.com/atlaste/CPPCoverage

说明:右键项目,运行覆盖。:-)

如果您更喜欢 XML 输出(用于 CI),则可以手动调用覆盖范围可执行文件。

于 2017-06-19T14:47:04.840 回答