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

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

问题描述

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



有人问我有关自动化测试代码覆盖率的问题。似乎在自动化工具之外,它是艺术而非科学。

解决方案

代码覆盖率是对多少行/块的度量。



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



我们的团队使用麦哲伦 –代码覆盖率工具。如果您是.NET商店,则Visual Studio具有集成的工具来收集代码覆盖率。您还可以使用一些自定义工具,例如本文描述。 p>

如果您是C ++商店,英特尔有一些用于Windows和Linux的工具,尽管我没有使用它们。我也听说过有GCC的gcov工具,但我对此一无所知,也无法给您链接。



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



BTW,而代码覆盖率是您进行多少测试的一个很好的指标,而不一定是您测试产品的质量的一个很好的指标。您还应该使用其他指标以及代码覆盖率来确保质量。


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天全站免登陆