询问 angular 2 单元测试中的 Coverage 摘要?

dan*_*hao 4 javascript unit-testing karma-coverage angular

当我在 angular 2 中运行测试时,我在 Coverage Summary 部分的控制台命令上看到一些关键字输出为Statements, Branches, Functions....

在此处输入图片说明

我不知道到底是什么?

任何帮助为我解释这一点,谢谢。

Pau*_*tha 8

  • 声明:我认为这篇文章很好地解释了它的声明。覆盖率测试您的所有语句都受到了打击。

  • 分支:当您使用条件时,它会创建分支

    if (condition) {
      doThis();       // this is a branch
    } else {
      doThat();       // this is a branch
    }
    
    Run Code Online (Sandbox Code Playgroud)

    您的测试是否覆盖所有分支?

  • 函数:您声明的函数。

    class SomeClas {
      methodOne() {}
      methodTwo() {}
    }
    
    it('..', () => {
      new SomeClass().methodOne();
    })
    
    Run Code Online (Sandbox Code Playgroud)

    SomeClass有两种方法,但只有一种正在接受测试。50%。如果您明确调用methodTwo测试或 methodOne调用methodTwo,则覆盖率将达到 100%

  • Lines::代码行,检查是否所有代码行都被命中。