diff --git a/pitest-entry/src/main/java/org/pitest/mutationtest/statistics/MutationStatistics.java b/pitest-entry/src/main/java/org/pitest/mutationtest/statistics/MutationStatistics.java index 18d5e0073..d359f830d 100644 --- a/pitest-entry/src/main/java/org/pitest/mutationtest/statistics/MutationStatistics.java +++ b/pitest-entry/src/main/java/org/pitest/mutationtest/statistics/MutationStatistics.java @@ -14,10 +14,13 @@ */ package org.pitest.mutationtest.statistics; +import org.pitest.classinfo.ClassName; + import java.io.PrintStream; import java.text.DecimalFormat; import java.text.DecimalFormatSymbols; import java.util.Locale; +import java.util.Set; public final class MutationStatistics { private final Iterable scores; @@ -26,13 +29,20 @@ public final class MutationStatistics { private final long totalDetected; private final long totalWithCoverage; - public MutationStatistics(Iterable scores, long totalMutations, - long totalDetected, long totalWithCoverage, long numberOfTestsRun) { + private final Set mutatedClasses; + + public MutationStatistics(Iterable scores, + long totalMutations, + long totalDetected, + long totalWithCoverage, + long numberOfTestsRun, + Set mutatedClasses) { this.scores = scores; this.totalMutations = totalMutations; this.totalDetected = totalDetected; this.numberOfTestsRun = numberOfTestsRun; this.totalWithCoverage = totalWithCoverage; + this.mutatedClasses = mutatedClasses; } public Iterable getScores() { @@ -59,6 +69,10 @@ public long getTotalSurvivingMutations() { return getTotalMutations() - getTotalDetectedMutations(); } + public Set mutatedClasses() { + return mutatedClasses; + } + public long getPercentageDetected() { if (getTotalMutations() == 0) { return 100; diff --git a/pitest-entry/src/main/java/org/pitest/mutationtest/statistics/MutationStatisticsListener.java b/pitest-entry/src/main/java/org/pitest/mutationtest/statistics/MutationStatisticsListener.java index 515bc6c55..f6246f8a5 100644 --- a/pitest-entry/src/main/java/org/pitest/mutationtest/statistics/MutationStatisticsListener.java +++ b/pitest-entry/src/main/java/org/pitest/mutationtest/statistics/MutationStatisticsListener.java @@ -43,6 +43,7 @@ public void runEnd() { } private void processMetaData(final ClassMutationResults value) { + this.mutatorScores.registerClass(value.getMutatedClass()); this.mutatorScores.registerResults(value.getMutations()); } } diff --git a/pitest-entry/src/main/java/org/pitest/mutationtest/statistics/MutationStatisticsPrecursor.java b/pitest-entry/src/main/java/org/pitest/mutationtest/statistics/MutationStatisticsPrecursor.java index 166c014e4..e3cde2864 100644 --- a/pitest-entry/src/main/java/org/pitest/mutationtest/statistics/MutationStatisticsPrecursor.java +++ b/pitest-entry/src/main/java/org/pitest/mutationtest/statistics/MutationStatisticsPrecursor.java @@ -2,21 +2,33 @@ import java.util.Collection; import java.util.HashMap; +import java.util.HashSet; import java.util.Map; +import java.util.Set; import java.util.function.BiFunction; import java.util.function.Consumer; +import org.pitest.classinfo.ClassName; import org.pitest.functional.FCollection; import org.pitest.mutationtest.MutationResult; class MutationStatisticsPrecursor { private final Map mutatorTotalMap = new HashMap<>(); + private final Set mutatedClasses = new HashSet<>(); private long numberOfTestsRun = 0; public void registerResults(final Collection results) { results.forEach(register()); } + public void registerClass(ClassName mutatedClass) { + mutatedClasses.add(mutatedClass); + } + + public Set mutatedClasses() { + return mutatedClasses; + } + private Consumer register() { return mr -> { MutationStatisticsPrecursor.this.numberOfTestsRun = MutationStatisticsPrecursor.this.numberOfTestsRun @@ -39,7 +51,7 @@ public MutationStatistics toStatistics() { .fold(addDetectedTotals(), 0L, scores); final long totalWithCoverage = FCollection.fold(addCoveredTotals(), 0L, scores); return new MutationStatistics(scores, totalMutations, totalDetected, totalWithCoverage, - this.numberOfTestsRun); + this.numberOfTestsRun, mutatedClasses()); } Iterable getScores() { @@ -58,4 +70,6 @@ private static BiFunction addDetectedTotals() { private static BiFunction addCoveredTotals() { return (a, b) -> a + b.getTotalWithCoverage(); } + + } \ No newline at end of file diff --git a/pitest-entry/src/main/java/org/pitest/mutationtest/tooling/MutationCoverage.java b/pitest-entry/src/main/java/org/pitest/mutationtest/tooling/MutationCoverage.java index 86710fbdb..814a14cc8 100644 --- a/pitest-entry/src/main/java/org/pitest/mutationtest/tooling/MutationCoverage.java +++ b/pitest-entry/src/main/java/org/pitest/mutationtest/tooling/MutationCoverage.java @@ -74,8 +74,10 @@ import java.util.function.Predicate; import java.util.logging.Level; import java.util.logging.Logger; +import java.util.stream.Collectors; import static java.util.Collections.emptyList; +import static java.util.Collections.emptySet; public class MutationCoverage { @@ -143,7 +145,7 @@ public CombinedStatistics runReport() throws IOException { } private CombinedStatistics emptyStatistics() { - MutationStatistics mutationStatistics = new MutationStatistics(emptyList(),0,0,0,0); + MutationStatistics mutationStatistics = new MutationStatistics(emptyList(),0,0,0,0, emptySet()); return new CombinedStatistics(mutationStatistics, new CoverageSummary(0,0), Collections.emptyList()); } @@ -185,8 +187,9 @@ private CombinedStatistics runAnalysis(Runtime runtime, long t0, EngineArguments LOG.info("Completed in " + timeSpan(t0)); - CombinedStatistics combined = new CombinedStatistics(stats.getStatistics(), - createSummary(modifiedCoverage), issues); + MutationStatistics mutationStats = stats.getStatistics(); + CombinedStatistics combined = new CombinedStatistics(mutationStats, + createSummary(modifiedCoverage, mutationStats.mutatedClasses()), issues); printStats(combined); @@ -199,12 +202,17 @@ private ReportCoverage transformCoverage(ReportCoverage coverageData) { return strategies.coverageTransformer().transform(coverageData); } - private CoverageSummary createSummary(ReportCoverage modifiedCoverage) { - int numberOfCodeLines = this.code.getCodeUnderTestNames().stream() - .map(c -> modifiedCoverage.getCodeLinesForClass(c).getNumberOfCodeLines()) + private CoverageSummary createSummary(ReportCoverage modifiedCoverage, Set mutatedClasses) { + List examinedClasses = this.code.getCodeUnderTestNames().stream() + .filter(mutatedClasses::contains) + .collect(Collectors.toList()); + + int numberOfCodeLines = examinedClasses.stream() + .map(c -> modifiedCoverage.getCodeLinesForClass(c)) + .map(c -> c.getNumberOfCodeLines()) .reduce(0, Integer::sum); - int coveredLines = this.code.getCodeUnderTestNames().stream() + int coveredLines = examinedClasses.stream() .mapToInt(c -> modifiedCoverage.getCoveredLines(c).size()) .sum(); @@ -324,7 +332,7 @@ private void printStats(CombinedStatistics combinedStatistics) { final CoverageSummary coverage = combinedStatistics.getCoverageSummary(); if (coverage != null) { - ps.println(String.format(">> Line Coverage: %d/%d (%d%%)", coverage.getNumberOfCoveredLines(), + ps.println(String.format(">> Line Coverage (for mutated classes only): %d/%d (%d%%)", coverage.getNumberOfCoveredLines(), coverage.getNumberOfLines(), coverage.getCoverage())); } diff --git a/pitest-maven/src/test/java/org/pitest/maven/PitMojoTest.java b/pitest-maven/src/test/java/org/pitest/maven/PitMojoTest.java index 59d7f2083..e36718d8c 100644 --- a/pitest-maven/src/test/java/org/pitest/maven/PitMojoTest.java +++ b/pitest-maven/src/test/java/org/pitest/maven/PitMojoTest.java @@ -396,7 +396,7 @@ public void testEmptyFeatureIsIgnored() throws Exception { private void setupCoverage(long mutationScore, int lines, int linesCovered) throws MojoExecutionException { Iterable scores = Collections.emptyList(); - final MutationStatistics stats = new MutationStatistics(scores, 100, mutationScore, 100, 0); + final MutationStatistics stats = new MutationStatistics(scores, 100, mutationScore, 100, 0, Collections.emptySet()); CoverageSummary sum = new CoverageSummary(lines, linesCovered); final CombinedStatistics cs = new CombinedStatistics(stats, sum, Collections.emptyList()); when( @@ -408,7 +408,7 @@ private void setupCoverage(long mutationScore, int lines, int linesCovered) private void setupTestStrength(long totalMutations, long mutationDetected, long mutationsWithCoverage) throws MojoExecutionException { Iterable scores = Collections.emptyList(); - final MutationStatistics stats = new MutationStatistics(scores, totalMutations, mutationDetected, mutationsWithCoverage, 0); + final MutationStatistics stats = new MutationStatistics(scores, totalMutations, mutationDetected, mutationsWithCoverage, 0, Collections.emptySet()); CoverageSummary sum = new CoverageSummary(0, 0); final CombinedStatistics cs = new CombinedStatistics(stats, sum, Collections.emptyList()); when( @@ -421,7 +421,7 @@ private void setupSuvivingMutants(long survivors) throws MojoExecutionException { Iterable scores = Collections.emptyList(); int detected = 100; - final MutationStatistics stats = new MutationStatistics(scores, detected + survivors, detected, detected + survivors, 0); + final MutationStatistics stats = new MutationStatistics(scores, detected + survivors, detected, detected + survivors, 0, Collections.emptySet()); CoverageSummary sum = new CoverageSummary(0, 0); final CombinedStatistics cs = new CombinedStatistics(stats, sum, Collections.emptyList()); when(