Skip to content
Permalink
Browse files

Report 100% for empty Coverage objects

If a section of code has no branches, we should report 100% branch coverage
not 0% coverage.  This prevents spurious threshold violations for such code.

(This concern also applies to other coverage measures, although in practice
I've only encountered this problem for branches.)

Fixes JENKINS-25076 and JENKINS-29117
  • Loading branch information...
Kevin Scaldeferri
Kevin Scaldeferri committed Feb 2, 2017
1 parent 2644b67 commit 174dbd90ab3ffbaaceb07664d57649cefc06d97d
BIN -2.2 KB (88%) resources/test/multiple.png
Binary file not shown.
@@ -66,7 +66,7 @@ public int getPercentage() {
public float getPercentageFloat() {
float numerator = covered;
float denominator = missed + covered;
return denominator <= 0 ? 0 : 100 * (numerator / denominator);
return denominator <= 0 ? 100 : 100 * (numerator / denominator);
}

public CoverageElement.Type getType() {
@@ -37,7 +37,7 @@ public void testNormalConstructorInitializes() throws Exception {

@Test
public void testVacuousCoverage() throws Exception {
Coverage c = new Coverage(0, 0);
assertEquals(0, c.getPercentage());
final Coverage c = new Coverage(0, 0);
assertEquals(100, c.getPercentage());
}
}
@@ -152,12 +152,12 @@ public void skipZero() throws IOException

private TestCoverageObject createTestCoverage()
{
TestCoverageObject t5 = new TestCoverageObject().branch(6, 30).line(5000, 19000);
TestCoverageObject t4 = new TestCoverageObject().branch(6, 0).line(5000, 19000).previous(t5);
TestCoverageObject t3 = new TestCoverageObject().branch(6, 35).line(5000, 19000).previous(t4);
TestCoverageObject t2 = new TestCoverageObject().branch(15, 23).line(10000, 15000).previous(t3);
TestCoverageObject t1 = new TestCoverageObject().branch(27, 13).line(12000, 18000).previous(t2);
TestCoverageObject t0 = new TestCoverageObject().previous(t1);
final TestCoverageObject t5 = new TestCoverageObject().branch(6, 30).line(5000, 19000);
final TestCoverageObject t4 = new TestCoverageObject().branch(6, 0).line(5000, 19000).previous(t5);
final TestCoverageObject t3 = new TestCoverageObject().branch(6, 35).line(5000, 19000).previous(t4);
final TestCoverageObject t2 = new TestCoverageObject().branch(15, 23).line(10000, 15000).previous(t3);
final TestCoverageObject t1 = new TestCoverageObject().branch(27, 13).line(12000, 18000).previous(t2);
final TestCoverageObject t0 = new TestCoverageObject().branch(40, 0).previous(t1);
ctl.replay();
return t0;
}
@@ -88,12 +88,12 @@ protected synchronized void saveNextBuildNumber() throws IOException {
}
};
assertTrue(jacocoColumn.hasCoverage(mockJob));
assertEquals("0.0", jacocoColumn.getPercent(mockJob));
assertEquals(new BigDecimal("0.0"), jacocoColumn.getLineCoverage(mockJob));
assertEquals("100.0", jacocoColumn.getPercent(mockJob));
assertEquals(new BigDecimal("100.0"), jacocoColumn.getLineCoverage(mockJob));

EasyMock.verify(context);
}

@Test
public void testGetLineColorWithNull() throws Exception {
assertNull(jacocoColumn.getLineColor(null, null));

0 comments on commit 174dbd9

Please sign in to comment.
You can’t perform that action at this time.