最佳答案
这些数字对应于该行在您的测试期间执行的次数。使用一个简单的例子:
public class MyClass {
public void methodA(){
System.out.println("Method a");
}
public void methodB(){
System.out.println("Method b");
}
}
通过一些测试:
public class MyClassTest {
@Test
public void testMethodA(){
final MyClass x = new MyClass();
x.methodA();
}
@Test
public void testMethodB(){
final MyClass x = new MyClass();
x.methodB();
}
}
我将得到以下报告,显示我构建了两次测试对象,并运行了每个方法一次:
如果我在 testMethodB
上添加一个 @Ignore
注释,则会生成以下报告,表明我只构造了一次我的类,并且没有在 中执行行code>methodB
测试时:
颜色与覆盖范围相关。当没有测试覆盖该行或分支时,它将显示为红色。
编辑 - 关于您在评论中的问题,由于未检查所有条件,可能会丢失覆盖范围。例如,考虑这个方法:
public void methodB(final boolean testOne, final boolean testTwo){
if(testOne || testTwo){
System.out.println("Method b");
}
System.out.println("Done");
}
和这个测试:
@Test
public void testMethodB(){
final MyClass x = new MyClass();
x.methodB(true, false);
x.methodB(true, true);
}
您将得到以下测试报告。这是因为虽然你确实在测试中执行了这一行(实际上是 2 次),但我没有测试我的条件的所有排列,因此,报告将显示我缺少覆盖。
关于maven - cobertura报告中行号旁边的颜色和数字是什么,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40181337/