diff --git a/pitest-aggregator/src/main/java/org/pitest/aggregate/ReportAggregator.java b/pitest-aggregator/src/main/java/org/pitest/aggregate/ReportAggregator.java index 4a684e351..876d8b927 100644 --- a/pitest-aggregator/src/main/java/org/pitest/aggregate/ReportAggregator.java +++ b/pitest-aggregator/src/main/java/org/pitest/aggregate/ReportAggregator.java @@ -138,7 +138,7 @@ private ReportCoverage calculateCoverage(final CodeSource codeSource) throws Rep Collection coverageData = this.blockCoverageLoader.loadData().stream() .map(BlockCoverage::getBlock) .collect(Collectors.toList()); - CoverageData cd = new CoverageData(codeSource, new LineMapper(codeSource)); + CoverageData cd = new CoverageData(codeSource, new LineMapper(codeSource), 0); cd.loadBlockDataOnly(coverageData); return transformCoverage(cd); diff --git a/pitest-entry/src/main/java/org/pitest/coverage/CoverageData.java b/pitest-entry/src/main/java/org/pitest/coverage/CoverageData.java index 25cfbaff7..17be31bec 100644 --- a/pitest-entry/src/main/java/org/pitest/coverage/CoverageData.java +++ b/pitest-entry/src/main/java/org/pitest/coverage/CoverageData.java @@ -42,14 +42,15 @@ public class CoverageData implements CoverageDatabase { private final Map> blockCoverage = new LinkedHashMap<>(); private final LegacyClassCoverage legacyClassCoverage; - private final CodeSource code; + private final int testCount; private final List failingTestDescriptions = new ArrayList<>(); - public CoverageData(final CodeSource code, final LineMap lm) { + public CoverageData(CodeSource code, LineMap lm, int testCount) { this.code = code; this.legacyClassCoverage = new LegacyClassCoverage(code, lm); + this.testCount = testCount; } public void calculateClassCoverage(final CoverageResult cr) { @@ -76,6 +77,11 @@ public Collection getTestsForBlockLocation(BlockLocation location) { return this.blockCoverage.getOrDefault(location, Collections.emptySet()); } + @Override + public int testCount() { + return testCount; + } + public boolean allTestsGreen() { return this.failingTestDescriptions.isEmpty(); } diff --git a/pitest-entry/src/main/java/org/pitest/coverage/CoverageDatabase.java b/pitest-entry/src/main/java/org/pitest/coverage/CoverageDatabase.java index 8ede4e551..6b884be99 100644 --- a/pitest-entry/src/main/java/org/pitest/coverage/CoverageDatabase.java +++ b/pitest-entry/src/main/java/org/pitest/coverage/CoverageDatabase.java @@ -7,6 +7,8 @@ public interface CoverageDatabase extends ReportCoverage { + int testCount(); + Collection getTestsForClass(ClassName clazz); Collection getTestsForBlockLocation(BlockLocation location); diff --git a/pitest-entry/src/main/java/org/pitest/coverage/CoverageSummary.java b/pitest-entry/src/main/java/org/pitest/coverage/CoverageSummary.java index 0662e97d6..fb2e4caf9 100644 --- a/pitest-entry/src/main/java/org/pitest/coverage/CoverageSummary.java +++ b/pitest-entry/src/main/java/org/pitest/coverage/CoverageSummary.java @@ -7,12 +7,18 @@ */ public final class CoverageSummary { + private final int numberOfTests; private final int numberOfLines; private final int numberOfCoveredLines; - public CoverageSummary(final int numberOfLines, final int numberOfCoveredLines) { + public CoverageSummary(int numberOfLines, int numberOfCoveredLines, int numberOfTests) { this.numberOfLines = numberOfLines; this.numberOfCoveredLines = numberOfCoveredLines; + this.numberOfTests = numberOfTests; + } + + public int getNumberOfTests() { + return this.numberOfTests; } public int getNumberOfLines() { diff --git a/pitest-entry/src/main/java/org/pitest/coverage/NoCoverage.java b/pitest-entry/src/main/java/org/pitest/coverage/NoCoverage.java index 7c3de5c6d..4ee420daa 100644 --- a/pitest-entry/src/main/java/org/pitest/coverage/NoCoverage.java +++ b/pitest-entry/src/main/java/org/pitest/coverage/NoCoverage.java @@ -18,6 +18,11 @@ public Set getCoveredLines(ClassName clazz) { return Collections.emptySet(); } + @Override + public int testCount() { + return 0; + } + @Override public Collection getTestsForClass(ClassName clazz) { return Collections.emptyList(); diff --git a/pitest-entry/src/main/java/org/pitest/coverage/execute/DefaultCoverageGenerator.java b/pitest-entry/src/main/java/org/pitest/coverage/execute/DefaultCoverageGenerator.java index 14f505656..aa6a1bdd2 100644 --- a/pitest-entry/src/main/java/org/pitest/coverage/execute/DefaultCoverageGenerator.java +++ b/pitest-entry/src/main/java/org/pitest/coverage/execute/DefaultCoverageGenerator.java @@ -90,7 +90,7 @@ public CoverageData calculateCoverage(Predicate testFilter) { this.timings.registerEnd(Timings.Stage.SCAN_CLASS_PATH); final CoverageData coverage = new CoverageData(this.code, new LineMapper( - this.code)); + this.code), tests.size()); this.timings.registerStart(Timings.Stage.COVERAGE); if (tests.isEmpty()) { 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 3533b4375..c84ddae35 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 @@ -148,7 +148,7 @@ public CombinedStatistics runReport() throws IOException { private CombinedStatistics emptyStatistics() { MutationStatistics mutationStatistics = new MutationStatistics(emptyList(),0,0,0,0, emptySet()); - return new CombinedStatistics(mutationStatistics, new CoverageSummary(0,0), Collections.emptyList()); + return new CombinedStatistics(mutationStatistics, new CoverageSummary(0,0, 0), Collections.emptyList()); } private CombinedStatistics runAnalysis(Runtime runtime, long t0, EngineArguments args, MutationEngine engine, List issues, List unfilteredMutants) { @@ -191,7 +191,7 @@ private CombinedStatistics runAnalysis(Runtime runtime, long t0, EngineArguments MutationStatistics mutationStats = stats.getStatistics(); CombinedStatistics combined = new CombinedStatistics(mutationStats, - createSummary(modifiedCoverage, mutationStats.mutatedClasses()), issues); + createSummary(coverageData.testCount(), modifiedCoverage, mutationStats.mutatedClasses()), issues); printStats(combined); @@ -204,7 +204,7 @@ private ReportCoverage transformCoverage(ReportCoverage coverageData) { return strategies.coverageTransformer().transform(coverageData); } - private CoverageSummary createSummary(ReportCoverage modifiedCoverage, Set mutatedClasses) { + private CoverageSummary createSummary(int numberOfTests, ReportCoverage modifiedCoverage, Set mutatedClasses) { List examinedClasses = this.code.getCodeUnderTestNames().stream() .filter(mutatedClasses::contains) .collect(Collectors.toList()); @@ -218,7 +218,7 @@ private CoverageSummary createSummary(ReportCoverage modifiedCoverage, Set modifiedCoverage.getCoveredLines(c).size()) .sum(); - return new CoverageSummary(numberOfCodeLines, coveredLines); + return new CoverageSummary(numberOfCodeLines, coveredLines, numberOfTests); } private Predicate allInterceptors() { @@ -318,6 +318,7 @@ private void printStats(CombinedStatistics combinedStatistics) { if (coverage != null) { ps.println(String.format(">> Line Coverage (for mutated classes only): %d/%d (%d%%)", coverage.getNumberOfCoveredLines(), coverage.getNumberOfLines(), coverage.getCoverage())); + ps.println(String.format(">> %d tests examined", coverage.getNumberOfTests())); } stats.report(ps); diff --git a/pitest-entry/src/test/java/org/pitest/coverage/CoverageDataTest.java b/pitest-entry/src/test/java/org/pitest/coverage/CoverageDataTest.java index bd9efd474..77483c1e0 100644 --- a/pitest-entry/src/test/java/org/pitest/coverage/CoverageDataTest.java +++ b/pitest-entry/src/test/java/org/pitest/coverage/CoverageDataTest.java @@ -70,7 +70,7 @@ public void setUp() { when(this.lm.mapLines(any(ClassName.class))).thenReturn( new HashMap<>()); when(this.code.findTestee(any())).thenReturn(Optional.empty()); - this.testee = new CoverageData(this.code, this.lm); + this.testee = new CoverageData(this.code, this.lm, 42); } @Test @@ -195,7 +195,7 @@ public void shouldProvideListOfClassesForSourceFile() { ClassTree barClass = treeFor(com.example.a.b.c.Bar.class); when(this.code.codeTrees()).thenReturn(Stream.of(fooClass, barClass)); - this.testee = new CoverageData(this.code, this.lm); + this.testee = new CoverageData(this.code, this.lm, 0); assertThat(this.testee.getClassesForFile("Bar.java", "com.example.a.b.c")) .containsExactly(new ClassLines(barClass.name(), Collections.emptySet())); @@ -209,13 +209,18 @@ public void shouldMatchPackageWhenFindingSources() { when(this.code.codeTrees()).thenReturn(classes.stream()); - this.testee = new CoverageData(this.code, this.lm); + this.testee = new CoverageData(this.code, this.lm, 0); assertThat(this.testee.getClassesForFile("Foo.java", "com.example.a.b.c")) .containsExactly(new ClassLines(foo1Class.name(), Collections.emptySet())); } + @Test + public void reportsTestCount() { + assertThat(testee.testCount()).isEqualTo(42); + } + private CoverageResult makeCoverageResult(final String clazz, final String testName, final int time, final int block) { return makeCoverageResult(clazz, new Description(testName), time, block, diff --git a/pitest-entry/src/test/java/org/pitest/coverage/CoverageSummaryTest.java b/pitest-entry/src/test/java/org/pitest/coverage/CoverageSummaryTest.java index a91cdae14..00ebe80bd 100644 --- a/pitest-entry/src/test/java/org/pitest/coverage/CoverageSummaryTest.java +++ b/pitest-entry/src/test/java/org/pitest/coverage/CoverageSummaryTest.java @@ -8,22 +8,22 @@ public class CoverageSummaryTest { @Test public void shouldCorrectlyCalculateLineCoverageWhenNoLinesPresent() { - assertEquals(100, new CoverageSummary(0, 0).getCoverage()); + assertEquals(100, new CoverageSummary(0, 0, 0).getCoverage()); } @Test public void shouldCorrectlyCalculateLineCoverageWhenNoLinesCovered() { - assertEquals(0, new CoverageSummary(100, 0).getCoverage()); + assertEquals(0, new CoverageSummary(100, 0, 0).getCoverage()); } @Test public void shouldCorrectlyCalculateLineCoverageWhenAllLinesCovered() { - assertEquals(100, new CoverageSummary(100, 100).getCoverage()); + assertEquals(100, new CoverageSummary(100, 100, 0).getCoverage()); } @Test public void shouldCorrectlyCalculateLineCoverageWhenPartiallyCovered() { - assertEquals(50, new CoverageSummary(100, 50).getCoverage()); + assertEquals(50, new CoverageSummary(100, 50, 0).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 afa965ec8..d1ab9f0d9 100644 --- a/pitest-maven/src/test/java/org/pitest/maven/PitMojoTest.java +++ b/pitest-maven/src/test/java/org/pitest/maven/PitMojoTest.java @@ -415,7 +415,7 @@ 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, Collections.emptySet()); - CoverageSummary sum = new CoverageSummary(lines, linesCovered); + CoverageSummary sum = new CoverageSummary(lines, linesCovered, 0); final CombinedStatistics cs = new CombinedStatistics(stats, sum, Collections.emptyList()); when( this.executionStrategy.execute(any(File.class), @@ -427,7 +427,7 @@ private void setupTestStrength(long totalMutations, long mutationDetected, long throws MojoExecutionException { Iterable scores = Collections.emptyList(); final MutationStatistics stats = new MutationStatistics(scores, totalMutations, mutationDetected, mutationsWithCoverage, 0, Collections.emptySet()); - CoverageSummary sum = new CoverageSummary(0, 0); + CoverageSummary sum = new CoverageSummary(0, 0, 0); final CombinedStatistics cs = new CombinedStatistics(stats, sum, Collections.emptyList()); when( this.executionStrategy.execute(any(File.class), @@ -440,7 +440,7 @@ private void setupSuvivingMutants(long survivors) Iterable scores = Collections.emptyList(); int detected = 100; final MutationStatistics stats = new MutationStatistics(scores, detected + survivors, detected, detected + survivors, 0, Collections.emptySet()); - CoverageSummary sum = new CoverageSummary(0, 0); + CoverageSummary sum = new CoverageSummary(0, 0, 0); final CombinedStatistics cs = new CombinedStatistics(stats, sum, Collections.emptyList()); when( this.executionStrategy.execute(any(File.class),