如何在Windows上使用gtest获取代码覆盖率?

时间:2022-07-23 15:08:34

I am using gtest for testing my code in C++ with Visual studio 2010. But I could not able to makeout that I have reached 100% code coverage. To make sure that I have covered 100% code coverage, I would like to know that, is there any way to find out the code coverage gtest or not? Because I have Googled a lot but I did not find any possible way to get the code coverage result by using gtest in Windows enviornment. If it is possible please let me know.

我正在使用gtest在Visual Studio 2010中用C ++测试我的代码。但是我无法证明我已达到100%的代码覆盖率。为了确保我已经涵盖了100%的代码覆盖率,我想知道,有没有办法找出代码覆盖率gtest与否?因为我已经搜索了很多,但我没有找到任何可能的方法来通过在Windows环境中使用gtest来获得代码覆盖率结果。如果有可能请告诉我。

Thanks A Lot..

非常感谢..

2 个解决方案

#1


4  

Code coverage in C++ can not be handled by the testing framework solely, because a coverage analysis tool has to know the whole extent of the code (wich the testing framework has not) and it has to instrument the code under test somehow to monitor wich parts of the code get executed.

C ++中的代码覆盖率不能仅由测试框架处理,因为覆盖率分析工具必须知道代码的整个范围(测试框架没有)并且必须以某种方式检测测试中的代码以监视部件代码被执行。

I had the same desire like you once, wanting to measure my test coverage in MSVC. This is what I learned:
MSVC ships with some command line tools for these instrumentations, googling a bit will get you one or two msdn blog posts about how to use them. Frankly, its not very convenient and easy to use. If you look for third party tools, you will probably not find any free ones. Any tools I found at all were enterprise tools with license fees in the range of several hundred to more than a thousand dollars, so not really an option if you are not a company.

我和你一样有同样的愿望,想要测量我在MSVC中的测试覆盖率。这就是我所学到的:MSVC附带了一些用于这些工具的命令行工具,谷歌搜索将获得一两篇关于如何使用它们的msdn博客文章。坦率地说,它不是很方便和易于使用。如果您寻找第三方工具,您可能找不到任何免费工具。我发现的任何工具都是企业工具,许可证费用在几百到一千多美元之间,所以如果你不是公司,那么这不是一个真正的选择。

#2


37  

You can try OpenCppCoverage: http://opencppcoverage.codeplex.com.

您可以尝试OpenCppCoverage:http://opencppcoverage.codeplex.com。

It is open source, designed for Visual Studio C++ and works well with Google Test. I already used successfully for mid size project (~500 000 lines of code).

它是开源的,专为Visual Studio C ++设计,适用于Google Test。我已成功用于中型项目(约500 000行代码)。

Hope that help.

希望有所帮助。

Disclaimer: I am the author of the tool.

免责声明:我是该工具的作者。

#1


4  

Code coverage in C++ can not be handled by the testing framework solely, because a coverage analysis tool has to know the whole extent of the code (wich the testing framework has not) and it has to instrument the code under test somehow to monitor wich parts of the code get executed.

C ++中的代码覆盖率不能仅由测试框架处理,因为覆盖率分析工具必须知道代码的整个范围(测试框架没有)并且必须以某种方式检测测试中的代码以监视部件代码被执行。

I had the same desire like you once, wanting to measure my test coverage in MSVC. This is what I learned:
MSVC ships with some command line tools for these instrumentations, googling a bit will get you one or two msdn blog posts about how to use them. Frankly, its not very convenient and easy to use. If you look for third party tools, you will probably not find any free ones. Any tools I found at all were enterprise tools with license fees in the range of several hundred to more than a thousand dollars, so not really an option if you are not a company.

我和你一样有同样的愿望,想要测量我在MSVC中的测试覆盖率。这就是我所学到的:MSVC附带了一些用于这些工具的命令行工具,谷歌搜索将获得一两篇关于如何使用它们的msdn博客文章。坦率地说,它不是很方便和易于使用。如果您寻找第三方工具,您可能找不到任何免费工具。我发现的任何工具都是企业工具,许可证费用在几百到一千多美元之间,所以如果你不是公司,那么这不是一个真正的选择。

#2


37  

You can try OpenCppCoverage: http://opencppcoverage.codeplex.com.

您可以尝试OpenCppCoverage:http://opencppcoverage.codeplex.com。

It is open source, designed for Visual Studio C++ and works well with Google Test. I already used successfully for mid size project (~500 000 lines of code).

它是开源的,专为Visual Studio C ++设计,适用于Google Test。我已成功用于中型项目(约500 000行代码)。

Hope that help.

希望有所帮助。

Disclaimer: I am the author of the tool.

免责声明:我是该工具的作者。