Asking about the Coverage summary in Unit test of angular 2?

空扰寡人 提交于 2019-12-13 14:23:33

问题


When I run test in angular 2 and I see a few keywords output on console command in Coverage Summary section as Statements, Branches, Functions....

And I don't know exactly what is it?

Any help explain this for me, thank you.


回答1:


  • Statement: I think this article does a pretty goo d job explaining what a statement it. The coverage tests that all your statements are getting hit.

  • Branch: When you use conditionals it create branches

    if (condition) {
      doThis();       // this is a branch
    } else {
      doThat();       // this is a branch
    }
    

    Is your testing hitting all the branches?

  • Functions: The functions that you declare.

    class SomeClas {
      methodOne() {}
      methodTwo() {}
    }
    
    it('..', () => {
      new SomeClass().methodOne();
    })
    

    SomeClass has two methods, but only one is getting tested. 50%. If you either explicitly call methodTwo in your test or methodOne calls methodTwo, your coverage goes to 100%

  • Lines:: The lines of code, checks to see if all the lines of code are being hit.



来源:https://stackoverflow.com/questions/40017929/asking-about-the-coverage-summary-in-unit-test-of-angular-2

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!