Skip to content

Commit

Permalink
Find occupied test packages if targetTests not provided, the same way…
Browse files Browse the repository at this point in the history
… it is done for targetClasses (#758)

Find occupied test packages if targetTests not provided, the same way it is done for targetClasses
  • Loading branch information
nicerloop authored Apr 24, 2020
1 parent 0cd1afe commit 003efd6
Show file tree
Hide file tree
Showing 5 changed files with 105 additions and 1 deletion.
10 changes: 10 additions & 0 deletions pitest-maven-verification/src/test/java/org/pitest/PitMojoIT.java
Original file line number Diff line number Diff line change
Expand Up @@ -552,5 +552,15 @@ private void verifyPitReportTest(File testDir) throws Exception {
.contains("<a href=\"pit-reports/index.html\" title=\"PIT Test Report\">PIT Test Report</a>"));
}

@Test
public void shouldFindOccupiedTestPackages() throws IOException, VerificationException {
File testDir = prepare("/pit-findOccupiedTestPackages");
verifier.executeGoal("test");
verifier.executeGoal("org.pitest:pitest-maven:mutationCoverage");

String actual = readResults(testDir);
assertThat(actual).contains(
"<mutation detected='true' status='KILLED' numberOfTestsRun='1'><sourceFile>DiscoveredClass.java</sourceFile>");
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<?xml version="1.0" encoding="UTF-8"?>
<project
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<modelVersion>4.0.0</modelVersion>
<groupId>com.example</groupId>
<artifactId>pitest-sample</artifactId>
<version>0.1-SNAPSHOT</version>
<name>pit maven findOccupiedTestPackages coverage</name>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>

<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.8.2</version>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.4</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
<plugin>
<groupId>org.pitest</groupId>
<artifactId>pitest-maven</artifactId>
<version>${pit.version}</version>
<configuration>
<verbose>true</verbose>
<outputFormats><value>XML</value></outputFormats>
<timestampedReports>false</timestampedReports>
<exportLineCoverage>true</exportLineCoverage>
</configuration>
</plugin>
</plugins>
</build>

</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package sources;

public class DiscoveredClass {

public int add(int a, int b) {
return a + b;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package tests;

import static junit.framework.Assert.assertEquals;

import org.junit.Test;

import sources.DiscoveredClass;

public class DiscoveredTest {

@Test
public void testAdd() {
assertEquals(2, new DiscoveredClass().add(1, 1));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,28 @@ private Collection<Predicate<String>> globStringsToPredicates(
}

private Collection<Predicate<String>> determineTargetTests() {
return FCollection.map(this.mojo.getTargetTests(), Glob.toGlobPredicate());
return FCollection.map(useConfiguredTargetTestsOrFindOccupiedPackages(this.mojo.getTargetTests()), Glob.toGlobPredicate());
}

private Collection<String> useConfiguredTargetTestsOrFindOccupiedPackages(
final Collection<String> filters) {
if (!hasValue(filters)) {
this.mojo.getLog().info("Defaulting target tests to match packages in test build directory");
return findOccupiedTestPackages();
} else {
return filters;
}
}

private Collection<String> findOccupiedTestPackages() {
String outputDirName = this.mojo.getProject().getBuild()
.getTestOutputDirectory();
if (outputDirName != null) {
File outputDir = new File(outputDirName);
return findOccupiedPackagesIn(outputDir);
} else {
return Collections.emptyList();
}
}

private Collection<Artifact> filteredDependencies() {
Expand Down

0 comments on commit 003efd6

Please sign in to comment.