Skip to content
Permalink
Browse files

pay tribute to healthyTarget as amplification factor for HealthReport…

… [FIXES JENKINS-20233]
  • Loading branch information...
madmuffin1 committed Aug 26, 2015
1 parent 167fcea commit 4b72095547da2d0cd1f3d0c9ebfe6230ea27ab1f
@@ -59,17 +59,22 @@ public HealthReport getBuildHealth() {
switch (minKey) {
case METHOD:
description = Messages._CloverBuildAction_MethodCoverage(
projectCoverage.getMethodCoverage().getPercentage(),
Ratio.create(
projectCoverage.getMethodCoverage().getPercentage(),
this.healthyTarget.getMethodCoverage()).getPercentage(),
projectCoverage.getMethodCoverage().toString());
break;
case STATEMENT:
description = Messages._CloverBuildAction_StatementCoverage(
projectCoverage.getStatementCoverage().getPercentage(),
Ratio.create(
projectCoverage.getStatementCoverage().getPercentage(),
this.healthyTarget.getStatementCoverage()).getPercentage(),
projectCoverage.getStatementCoverage().toString());
break;
case ELEMENT:
description = Messages._CloverBuildAction_ElementCoverage(
projectCoverage.getElementCoverage().getPercentage(),
Ratio.create(projectCoverage.getElementCoverage().getPercentage(),
this.healthyTarget.getStatementCoverage()).getPercentage(),
projectCoverage.getElementCoverage().toString());
break;
default:
@@ -1,6 +1,7 @@
package org.jenkinsci.plugins.cloverphp;

import hudson.model.AbstractBuild;
import hudson.model.HealthReport;
import hudson.model.Result;
import org.jenkinsci.plugins.cloverphp.results.ProjectCoverage;
import org.jenkinsci.plugins.cloverphp.targets.CoverageTarget;
@@ -133,4 +134,34 @@ public void testPreviousResult() {
assertNull(action.getPreviousResult());
}

@Test
public void testHealthReportAmplification() {
// GIVEN a build with some coverage metrics
AbstractBuild<?, ?> build = mock(AbstractBuild.class);
String workspacePath = "/tmp/workpath";
ProjectCoverage prjCoverage = new ProjectCoverage();
CoverageTarget healthyTarget = new CoverageTarget();
CoverageTarget unhealthyTarget = new CoverageTarget();

prjCoverage.setCoveredelements(300);
prjCoverage.setElements(1000);
healthyTarget.setElementCoverage(30); // 300/1000 = 30%, target 30% => 100% match

prjCoverage.setCoveredstatements(300);
prjCoverage.setStatements(1000);
healthyTarget.setStatementCoverage(40); // 300/1000 = 30%, target 40% => 75% match

prjCoverage.setCoveredmethods(300);
prjCoverage.setMethods(1000);
healthyTarget.setMethodCoverage(50); // 300/1000 = 30%, target 50% => 60% match

CloverBuildAction action = new CloverBuildAction(build, workspacePath, prjCoverage, healthyTarget, unhealthyTarget);

// WHEN calculating the health report
HealthReport healthReport = action.getBuildHealth();

// IT shoud
assertEquals("return 60% score, as this is the lowest value", 60, healthReport.getScore());
}

}

0 comments on commit 4b72095

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