什么是代码覆盖率以及如何衡量它? [英] What is code coverage and how do YOU measure it?

查看:29
本文介绍了什么是代码覆盖率以及如何衡量它?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

什么是代码覆盖率以及如何衡量它?

有人问我这个关于我们自动化测试代码覆盖率的问题.似乎在自动化工具之外,它更像是艺术而不是科学.是否有任何关于如何使用代码覆盖率的真实示例?

解决方案

代码覆盖率是衡量自动化测试运行时执行了多少行/块/弧的代码.

代码覆盖率是通过使用专门的工具来检测二进制文件以添加跟踪调用并针对已检测的产品运行一整套自动化测试来收集的.一个好的工具不仅可以为您提供已执行代码的百分比,还可以让您深入了解数据并准确查看在特定测试期间执行了哪些代码行.

我们的团队使用 Magellan - 一套内部代码覆盖工具.如果您是 .NET 商店,Visual Studio 已集成工具来收集代码覆盖率.您还可以滚动一些自定义工具,例如本文介绍.>

如果您是 C++ 商店,英特尔有一些 工具 运行在 Windows 和 Linux 上,虽然我没有使用过它们.我也听说有 GCC 的 gcov 工具,但我对此一无所知,无法提供链接.

至于我们如何使用它 - 代码覆盖率是我们每个里程碑的退出标准之一.我们实际上有三个代码覆盖率指标 - 单元测试覆盖率(来自开发团队)、场景测试覆盖率(来自测试团队)和组合覆盖率.

顺便说一句,虽然代码覆盖率是衡量您进行了多少测试的一个很好的衡量标准,但它不一定是衡量您的产品测试效果的一个很好的衡量标准.您还应该使用其他指标以及代码覆盖率来确保质量.

What is code coverage and how do YOU measure it?

I was asked this question regarding our automating testing code coverage. It seems to be that, outside of automated tools, it is more art than science. Are there any real-world examples of how to use code coverage?

解决方案

Code coverage is a measurement of how many lines/blocks/arcs of your code are executed while the automated tests are running.

Code coverage is collected by using a specialized tool to instrument the binaries to add tracing calls and run a full set of automated tests against the instrumented product. A good tool will give you not only the percentage of the code that is executed, but also will allow you to drill into the data and see exactly which lines of code were executed during a particular test.

Our team uses Magellan - an in-house set of code coverage tools. If you are a .NET shop, Visual Studio has integrated tools to collect code coverage. You can also roll some custom tools, like this article describes.

If you are a C++ shop, Intel has some tools that run for Windows and Linux, though I haven't used them. I've also heard there's the gcov tool for GCC, but I don't know anything about it and can't give you a link.

As to how we use it - code coverage is one of our exit criteria for each milestone. We have actually three code coverage metrics - coverage from unit tests (from the development team), scenario tests (from the test team) and combined coverage.

BTW, while code coverage is a good metric of how much testing you are doing, it is not necessarily a good metric of how well you are testing your product. There are other metrics you should use along with code coverage to ensure the quality.

这篇关于什么是代码覆盖率以及如何衡量它?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆