如何阅读伊斯坦布尔覆盖报告? [英] How do I read an Istanbul Coverage Report?

查看:19
本文介绍了如何阅读伊斯坦布尔覆盖报告?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直使用 Jasmine 进行单元测试,但最近我开始使用 Istanbul 来为我提供代码覆盖率报告.我的意思是我得到了他们试图告诉我的gist,但我真的不知道这些百分比中的每一个代表什么(Stmts、Branches、Funcs、Lines).到目前为止,谷歌搜索我一直无法找到可靠的解释/资源.

I've always used Jasmine for my unit tests, but recently I started using Istanbul to give me code coverage reports. I mean I get the gist of what they are trying to tell me, but I don't really know what each of these percentages represent (Stmts, Branches, Funcs, Lines). So far Googling I have been unable to find a solid explanation/resource.

问题:就像我说的那样,我明白了要点,但是有人可以发布正确的解释或指向正确解释的链接吗?

Question: Like I said I get the gist of it, but can someone post either a proper explanation or a link to a proper explanation?

第三个问题:有什么方法可以确定代码的哪些特定部分没有被覆盖?到目前为止,我还没有真正理解这份报告,我基本上是在猜测.

Tertiary Question: Is there any way to identify what specific parts of your code aren't covered? So far without really grokking this report I'm basically guessing.

-------------------|-----------|-----------|-----------|-----------|
File               |   % Stmts |% Branches |   % Funcs |   % Lines |
-------------------|-----------|-----------|-----------|-----------|
   controllers/    |      88.1 |     77.78 |     78.57 |      88.1 |
      dashboard.js |      88.1 |     77.78 |     78.57 |      88.1 |
-------------------|-----------|-----------|-----------|-----------|
All files          |      88.1 |     77.78 |     78.57 |      88.1 |
-------------------|-----------|-----------|-----------|-----------|

推荐答案

有很多覆盖标准,主要有:

There are a number of coverage criteria, the main ones being:

  • 函数覆盖率 程序中的每个函数(或子程序)是否被调用过?
  • 语句覆盖率 程序中的每条语句都执行了吗?
  • 分支覆盖 每个控制结构(例如 if 和 case 语句)的每个分支(也称为 DD 路径)是否已执行?例如,给定一个 if 语句,是否同时执行了 true 和 false 分支?另一种说法是,程序中的每一条边都执行了吗?
  • 行覆盖率是否已执行源文件中的每个可执行行?
  • Function coverage Has each function (or subroutine) in the program been called?
  • Statement coverage Has each statement in the program been executed?
  • Branch coverage Has each branch (also called DD-path) of each control structure (such as in if and case statements) been executed? For example, given an if statement, have both the true and false branches been executed? Another way of saying this is, has every edge in the program been executed?
  • Line coverage has each executable line in the source file been executed?

对于每种情况,百分比代表执行的代码未执行的代码,它等于百分比格式的每个分数(例如:50% 分支,1/2).

For each case, the percentage represents executed code vs not-executed code, which equals each fraction in percent format (e.g: 50% branches, 1/2).

在文件报告中:

  • 'E'代表'else path not taken',意思是对于标记的if/else语句,'if'路径已经被测试过,'else'路径没有被测试过.李>
  • 'I' 代表如果路径未采用",这是相反的情况:如果"尚未经过测试.
  • 左列中的 xN 是该行已执行的次数.
  • 未执行的行或代码片段将以红色突出显示.
  • 'E' stands for 'else path not taken', which means that for the marked if/else statement, the 'if' path has been tested but not the 'else'.
  • 'I' stands for 'if path not taken', which is the opposite case: the 'if' hasn't been tested.
  • The xN in left column is the amount of times that line has been executed.
  • Not executed lines, or pieces of code, will be highlighted in red.

这已在伊斯坦布尔 v0.4.0 中得到验证,我不确定这是否仍适用于后续版本,但由于该库基于可靠的理论原则,因此对于新版本的行为不应改变太多.

This has been verified for Istanbul v0.4.0, I'm not sure if this still applies for subsequent versions, but being that library is based on solid theoretic principles, behavior shouldn't change too much for newer versions.

它还提供了一些颜色代码 -

It also provides some color codes -

粉红色:声明未涵盖.

橙色:未涵盖的功能.

黄色:树枝没有被覆盖.

这里有完整的伊斯坦布尔文档:

Full Istanbul docs here:

https://istanbul.js.org

更深入的代码覆盖理论:

For more in-depth theory on code coverage:

https://en.wikipedia.org/wiki/Code_coverage

希望对你有帮助!

这篇关于如何阅读伊斯坦布尔覆盖报告?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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