什么是代码覆盖率的替代指标? [英] What can be alternative metrics to code coverage?

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

问题描述

代码覆盖率可能是最具争议的代码指标。有人说,您必须达到80%的代码覆盖率,而有人说,这是肤浅的,并且没有说明您的测试质量。 (请参阅 Jon Limjap对什么是单元测试的合理代码覆盖率百分比(以及为什么)? 。)

Code coverage is propably the most controversial code metric. Some say, you have to reach 80% code coverage, other say, it's superficial and does not say anything about your testing quality. (See Jon Limjap's good answer on "What is a reasonable code coverage % for unit tests (and why)?".)

人们倾向于衡量一切。他们需要比较,基准测试等。

项目团队需要一个指针,他们的测试水平如何。

People tend to measure everything. They need comparisons, benchmarks etc.
Project teams need a pointer, how good their testing is.

那么代码覆盖率的替代方法是什么?哪个指标比我接触过这行代码还要好?

是否有其他替代方案?

So what are alternatives to code coverage? What would be a good metric that says more than "I touched this line of code"?
Are there real alternatives?

推荐答案

如果您正在寻找一些有用的指标来告诉您有关代码质量(或缺少指标)的信息,则应研究以下指标:

If you are looking for some useful metrics that tell you about the quality (or lack there of) of your code, you should look into the following metrics:


  1. 循环复杂度


    • 这是一种方法的复杂程度的度量。

    • 通常10岁以下的人是好人,11-25岁的人是穷人,更高的人则很糟糕。


  • 这是一个方法中嵌套范围的度量。

  • 通常小于等于4是好,5-8是差,更高是可怕的。


  • 这是衡量包或程序集中的类型之间相关性的度量。

  • 关系内聚在某种程度上是相对度量,但仍然很有用。 / li>
  • 可接受的水平取决于公式。给定以下内容:


    • R:包/组合中的关系数

    • N:包/中的类型数程序集

    • H:类型之间关系的内聚力

    • This is a measure of how well related the types in a package or assembly are.
    • Relational cohesion is somewhat of a relative metric, but useful none the less.
    • Acceptable levels depends on the formula. Given the following:
      • R: number of relationships in package/assembly
      • N: number of types in package/assembly
      • H: Cohesion of relationship between types
查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆