Skip to content

Commit

Permalink
Add test strength metric.
Browse files Browse the repository at this point in the history
  • Loading branch information
uhafner committed Jan 17, 2024
1 parent c847de6 commit 83a53b3
Show file tree
Hide file tree
Showing 12 changed files with 55 additions and 24 deletions.
2 changes: 1 addition & 1 deletion plugin/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
<gitHubRepo>jenkinsci/coverage-plugin</gitHubRepo>

<!-- Library Dependencies Versions -->
<coverage-model.version>0.37.0</coverage-model.version>
<coverage-model.version>0.38.0</coverage-model.version>
<jsoup.version>1.17.2</jsoup.version>

<!-- Jenkins Plug-in Dependencies Versions -->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,21 +19,26 @@ public class CoverageSeriesBuilder extends SeriesBuilder<CoverageStatistics> {
static final String LINE_COVERAGE = "line";
static final String BRANCH_COVERAGE = "branch";
static final String MUTATION_COVERAGE = "mutation";
static final String TEST_STRENGTH = "test-strength";

@Override
protected Map<String, Double> computeSeries(final CoverageStatistics statistics) {
Map<String, Double> series = new HashMap<>();

series.put(LINE_COVERAGE, getRoundedPercentage(statistics, Metric.LINE));
if (statistics.containsValue(Baseline.PROJECT, Metric.BRANCH)) {
series.put(BRANCH_COVERAGE, getRoundedPercentage(statistics, Metric.BRANCH));
}
if (statistics.containsValue(Baseline.PROJECT, Metric.MUTATION)) {
series.put(MUTATION_COVERAGE, getRoundedPercentage(statistics, Metric.MUTATION));
}
add(statistics, Metric.BRANCH, BRANCH_COVERAGE, series);
add(statistics, Metric.MUTATION, MUTATION_COVERAGE, series);
add(statistics, Metric.TEST_STRENGTH, TEST_STRENGTH, series);
return series;
}

private void add(final CoverageStatistics statistics, final Metric metric, final String chartId,
final Map<String, Double> series) {
if (statistics.containsValue(Baseline.PROJECT, metric)) {
series.put(chartId, getRoundedPercentage(statistics, metric));
}
}

private double getRoundedPercentage(final CoverageStatistics statistics, final Metric metric) {
Coverage coverage = (Coverage) statistics.getValue(Baseline.PROJECT, metric)
.orElse(Coverage.nullObject(metric));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,6 @@
* @see JacksonFacade
*/
public class CoverageTrendChart {
private static final String LINE_COVERAGE_COLOR = JenkinsPalette.GREEN.normal();
private static final String BRANCH_COVERAGE_COLOR = JenkinsPalette.GREEN.dark();

/**
* Creates the chart for the specified results.
*
Expand All @@ -45,24 +42,28 @@ public LinesChartModel create(final Iterable<BuildResult<CoverageStatistics>> re
LinesChartModel model = new LinesChartModel(dataSet);
if (dataSet.isNotEmpty()) {
LineSeries lineSeries = new LineSeries(Messages.Metric_LINE(),
LINE_COVERAGE_COLOR, StackedMode.SEPARATE_LINES, FilledMode.FILLED,
JenkinsPalette.GREEN.normal(), StackedMode.SEPARATE_LINES, FilledMode.FILLED,
dataSet.getSeries(CoverageSeriesBuilder.LINE_COVERAGE));
model.addSeries(lineSeries);
model.useContinuousRangeAxis();
model.setRangeMax(100);
model.setRangeMin(dataSet.getMinimumValue());

addSecondSeries(dataSet, model, Messages.Metric_BRANCH(), CoverageSeriesBuilder.BRANCH_COVERAGE);
addSecondSeries(dataSet, model, Messages.Metric_MUTATION(), CoverageSeriesBuilder.MUTATION_COVERAGE);
addSeries(dataSet, model, Messages.Metric_BRANCH(), CoverageSeriesBuilder.BRANCH_COVERAGE,
JenkinsPalette.GREEN.dark());
addSeries(dataSet, model, Messages.Metric_MUTATION(), CoverageSeriesBuilder.MUTATION_COVERAGE,
JenkinsPalette.GREEN.dark());
addSeries(dataSet, model, Messages.Metric_TEST_STRENGTH(), CoverageSeriesBuilder.TEST_STRENGTH,
JenkinsPalette.GREEN.light());
}
return model;
}

private static void addSecondSeries(final LinesDataSet dataSet, final LinesChartModel model,
final String name, final String seriesId) {
private static void addSeries(final LinesDataSet dataSet, final LinesChartModel model,
final String name, final String seriesId, final String color) {
if (dataSet.containsSeries(seriesId)) {
LineSeries branchSeries = new LineSeries(name,
BRANCH_COVERAGE_COLOR, StackedMode.SEPARATE_LINES, FilledMode.FILLED,
color, StackedMode.SEPARATE_LINES, FilledMode.FILLED,
dataSet.getSeries(seriesId));

model.addSeries(branchSeries);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,9 +136,9 @@ public String formatDetails(final Value value, final Locale locale) {

/**
* Formats additional information for a generic value using a specific rendering method. This information can be
* added as a tooltip. The type of the given {@link Value} instance is used to select the best matching rendering
* method. This non-object-oriented approach is required since the {@link Value} instances are provided by a library
* that is not capable of localizing these values for the user.
* added as a tooltip. The type of the given {@link Value} instance is used to select the best matching
* rendering method. This non-object-oriented approach is required since the {@link Value} instances are
* provided by a library that is not capable of localizing these values for the user.
*
* @param value
* the value to format
Expand All @@ -149,7 +149,8 @@ public String formatAdditionalInformation(final Value value) {
if (value instanceof Coverage) {
var coverage = (Coverage) value;
if (coverage.isSet()) {
if (coverage.getMetric() == Metric.MUTATION) {
if (coverage.getMetric() == Metric.MUTATION

Check warning on line 152 in plugin/src/main/java/io/jenkins/plugins/coverage/metrics/model/ElementFormatter.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Partially covered line

Line 152 is only partially covered, one branch is missing
|| coverage.getMetric() == Metric.TEST_STRENGTH) {

Check warning on line 153 in plugin/src/main/java/io/jenkins/plugins/coverage/metrics/model/ElementFormatter.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Partially covered line

Line 153 is only partially covered, one branch is missing
return formatCoverage(coverage, Messages.Metric_MUTATION_Killed(),
Messages.Metric_MUTATION_Survived());
}
Expand All @@ -158,7 +159,6 @@ public String formatAdditionalInformation(final Value value) {
Messages.Metric_Coverage_Missed());
}
}
return StringUtils.EMPTY;
}
return StringUtils.EMPTY;
}
Expand Down Expand Up @@ -387,6 +387,8 @@ public String getDisplayName(final Metric metric) {
return Messages.Metric_INSTRUCTION();
case MUTATION:
return Messages.Metric_MUTATION();
case TEST_STRENGTH:
return Messages.Metric_TEST_STRENGTH();
case COMPLEXITY:
return Messages.Metric_COMPLEXITY();
case COMPLEXITY_MAXIMUM:
Expand Down Expand Up @@ -458,6 +460,8 @@ public String getLabel(final Metric metric) {
return Messages.Metric_Short_INSTRUCTION();
case MUTATION:
return Messages.Metric_Short_MUTATION();
case TEST_STRENGTH:
return Messages.Metric_Short_TEST_STRENGTH();

Check warning on line 464 in plugin/src/main/java/io/jenkins/plugins/coverage/metrics/model/ElementFormatter.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Not covered line

Line 464 is not covered by tests

Check warning on line 464 in plugin/src/main/java/io/jenkins/plugins/coverage/metrics/model/ElementFormatter.java

View check run for this annotation

Codecov / codecov/patch

plugin/src/main/java/io/jenkins/plugins/coverage/metrics/model/ElementFormatter.java#L464

Added line #L464 was not covered by tests
case COMPLEXITY:
return Messages.Metric_Short_COMPLEXITY();
case COMPLEXITY_MAXIMUM:
Expand Down Expand Up @@ -518,6 +522,7 @@ public ListBoxModel getMetricItems() {
add(options, Metric.BRANCH);
add(options, Metric.INSTRUCTION);
add(options, Metric.MUTATION);
add(options, Metric.TEST_STRENGTH);
add(options, Metric.COMPLEXITY);
add(options, Metric.COMPLEXITY_MAXIMUM);
add(options, Metric.LOC);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -570,7 +570,8 @@ public double getTrend(final Baseline baseline, final Metric metric) {
@VisibleForTesting
NavigableSet<Metric> getMetricsForSummary() {
return new TreeSet<>(
Set.of(Metric.LINE, Metric.LOC, Metric.BRANCH, Metric.COMPLEXITY_DENSITY, Metric.MUTATION, Metric.TESTS));
Set.of(Metric.LINE, Metric.LOC, Metric.BRANCH, Metric.COMPLEXITY_DENSITY,
Metric.MUTATION, Metric.TEST_STRENGTH, Metric.TESTS));
}

/**
Expand All @@ -586,7 +587,7 @@ NavigableSet<Metric> getMetricsForSummary() {
}

/**
* Renders the reference build as HTML-link.
* Renders the reference build as an HTML link.
*
* @return the reference build
* @see #getReferenceBuild()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,8 @@ public List<TableColumn> getColumns() {
Messages.Column_DeltaBranchCoverage("Δ"), columns);
configureValueColumn("mutationCoverage", Metric.MUTATION, Messages.Column_MutationCoverage(),
Messages.Column_DeltaMutationCoverage("Δ"), columns);
configureValueColumn("testStrength", Metric.TEST_STRENGTH, Messages.Column_TestStrength(),
Messages.Column_DeltaTestStrength("Δ"), columns);

Check warning on line 123 in plugin/src/main/java/io/jenkins/plugins/coverage/metrics/steps/CoverageTableModel.java

View check run for this annotation

Codecov / codecov/patch

plugin/src/main/java/io/jenkins/plugins/coverage/metrics/steps/CoverageTableModel.java#L122-L123

Added lines #L122 - L123 were not covered by tests
TableColumn loc = new ColumnBuilder().withHeaderLabel(Messages.Column_LinesOfCode())
.withDataPropertyKey("loc")
.withResponsivePriority(200)
Expand Down Expand Up @@ -251,6 +253,10 @@ public DetailedCell<?> getMutationCoverage() {
return createColoredCoverageColumn(getCoverageOfNode(Metric.MUTATION));
}

public DetailedCell<?> getTestStrength() {
return createColoredCoverageColumn(getCoverageOfNode(Metric.TEST_STRENGTH));

Check warning on line 257 in plugin/src/main/java/io/jenkins/plugins/coverage/metrics/steps/CoverageTableModel.java

View check run for this annotation

Codecov / codecov/patch

plugin/src/main/java/io/jenkins/plugins/coverage/metrics/steps/CoverageTableModel.java#L257

Added line #L257 was not covered by tests
}

Coverage getCoverageOfNode(final Metric metric) {
return file.getTypedValue(metric, Coverage.nullObject(metric));
}
Expand All @@ -267,6 +273,10 @@ public DetailedCell<?> getMutationCoverageDelta() {
return createColoredFileCoverageDeltaColumn(Metric.MUTATION);
}

public DetailedCell<?> getTestStrengthDelta() {
return createColoredFileCoverageDeltaColumn(Metric.TEST_STRENGTH);

Check warning on line 277 in plugin/src/main/java/io/jenkins/plugins/coverage/metrics/steps/CoverageTableModel.java

View check run for this annotation

Codecov / codecov/patch

plugin/src/main/java/io/jenkins/plugins/coverage/metrics/steps/CoverageTableModel.java#L277

Added line #L277 was not covered by tests
}

public int getLoc() {
return file.getTypedValue(Metric.LOC, ZERO_LOC).getValue();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ public class CoverageViewModel extends DefaultAsyncTableContentProvider implemen

private static final ElementFormatter FORMATTER = new ElementFormatter();
private static final Set<Metric> TREE_METRICS = Set.of(
Metric.LINE, Metric.BRANCH, Metric.MUTATION, Metric.COMPLEXITY, Metric.TESTS);
Metric.LINE, Metric.BRANCH, Metric.MUTATION, Metric.TEST_STRENGTH, Metric.COMPLEXITY, Metric.TESTS);
private static final String UNDEFINED = "-";
private final Run<?, ?> owner;
private final String displayName;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ Metric.METHOD=Method Coverage
Metric.INSTRUCTION=Instruction Coverage
Metric.LINE=Line Coverage
Metric.MUTATION=Mutation Coverage
Metric.TEST_STRENGTH=Test Strength
Metric.BRANCH=Branch Coverage
Metric.COMPLEXITY=Cyclomatic Complexity
Metric.COMPLEXITY_DENSITY=Complexity Density
Expand All @@ -23,6 +24,7 @@ Metric.Short.METHOD=Method
Metric.Short.INSTRUCTION=Instruction
Metric.Short.LINE=Line
Metric.Short.MUTATION=Mutation
Metric.Short.TEST_STRENGTH=Test Strength
Metric.Short.BRANCH=Branch
Metric.Short.COMPLEXITY=Complexity
Metric.Short.COMPLEXITY_DENSITY=Complexity Density
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
<dd>Branch coverage or decision coverage (given as percentage)</dd>
<dt>MUTATION</dt>
<dd>Mutation coverage (given as percentage)</dd>
<dt>TEST_STRENGTH</dt>
<dd>Test Strength (given as percentage)</dd>
<dt>COMPLEXITY</dt>
<dd>Cyclomatic complexity (given as absolute number)</dd>
<dt>COMPLEXITY_DENSITY</dt>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
<dd>Branch coverage or decision coverage (given as percentage)</dd>
<dt>MUTATION</dt>
<dd>Mutation coverage (given as percentage)</dd>
<dt>TEST_STRENGTH</dt>
<dd>Test Strength (given as percentage)</dd>
<dt>COMPLEXITY</dt>
<dd>Cyclomatic complexity (given as absolute number)</dd>
<dt>COMPLEXITY_DENSITY</dt>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@ Column.DeltaLineCoverage=Line {0}
Column.BranchCoverage=Branch
Column.DeltaBranchCoverage=Branch {0}
Column.MutationCoverage=Mutation
Column.TestStrength=Test Strength
Column.DeltaMutationCoverage=Mutation {0}
Column.DeltaTestStrength=Test Strength {0}
Column.LinesOfCode=LOC
Column.Tests=Tests
Column.Complexity=Complexity
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
* **[Overall project (difference to reference job)](http://127.0.0.1:8080/job/pipeline-coding-style/job/5/coverage#overview)**
* Line Coverage: 93.84% (198/211) - Delta: +50.00%
* Mutation Coverage: 90.24% (222/246)
* Test Strength: 96.52% (222/230)
* Lines of Code: 211
* **[Modified files (difference to reference job)](http://127.0.0.1:8080/job/pipeline-coding-style/job/5/coverage#modifiedFilesCoverage)**
* Line Coverage: 50.00% (1/2) - Delta: +50.00%
Expand Down

0 comments on commit 83a53b3

Please sign in to comment.