Differences between Line and Branch coverage

前端 未结 3 1835
[愿得一人]
[愿得一人] 2020-12-22 21:27

I use the Cobertura Maven plugin for one of my project. But I have a question about the generated report:

What is the difference between line and branch coverage?

3条回答
  •  死守一世寂寞
    2020-12-22 22:01

    Take this code as a simplified example:

    if(cond) {
        line1();
        line2();
        line3();
        line4();
    } else {
        line5();
    }
    

    If your test only exercises the cond being true and never runs the else branch you have:

    • 4 out of 5 lines covered
    • 1 out of 2 branches covered

    Also Cobertura report itself introduces some nice pop-up help tooltips when column header is clicked:

    Line Coverage - The percent of lines executed by this test run.

    Branch Coverage - The percent of branches executed by this test run.

提交回复
热议问题