我一直使用 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:
对于每种情况,百分比代表执行的代码与未执行的代码,它等于百分比格式的每个分数(例如: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.xN
in left column is the amount of times that line has been executed.这已在伊斯坦布尔 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
希望对你有帮助!
这篇关于如何阅读伊斯坦布尔覆盖报告?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!