From 7b19bf037d6f759425d9548b236ca0c479bea6bb Mon Sep 17 00:00:00 2001 From: Peter Date: Sun, 30 Jan 2022 12:31:07 +0100 Subject: [PATCH 1/2] #750 -DskipTests Flag should be honoured in a maven run without additional configuration --- .../src/test/java/org/pitest/PitMojoIT.java | 8 +++----- .../src/main/java/org/pitest/maven/AbstractPitMojo.java | 2 +- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/pitest-maven-verification/src/test/java/org/pitest/PitMojoIT.java b/pitest-maven-verification/src/test/java/org/pitest/PitMojoIT.java index 5d17fe634..936a741f6 100755 --- a/pitest-maven-verification/src/test/java/org/pitest/PitMojoIT.java +++ b/pitest-maven-verification/src/test/java/org/pitest/PitMojoIT.java @@ -32,6 +32,7 @@ import org.slf4j.LoggerFactory; import java.io.File; +import java.io.FileNotFoundException; import java.io.IOException; import java.io.InputStream; import java.util.Properties; @@ -353,17 +354,14 @@ public void shouldCorrectlyHandleOverrides() throws Exception { buildFilePath(testDir, "target", "site", "pit-reports").exists()); } - @Test + @Test(expected = FileNotFoundException.class) public void shouldReadExclusionsFromSurefireConfig() throws Exception { File testDir = prepare("/pit-surefire-excludes"); verifier.addCliOption("-DskipTests"); verifier.executeGoal("test"); verifier.executeGoal("org.pitest:pitest-maven:mutationCoverage"); - String actual = readResults(testDir); - assertThat(actual) - .contains( - "NotCovered.java"); + readResults(testDir); } @Test diff --git a/pitest-maven/src/main/java/org/pitest/maven/AbstractPitMojo.java b/pitest-maven/src/main/java/org/pitest/maven/AbstractPitMojo.java index a3b56f24e..4224e8b36 100644 --- a/pitest-maven/src/main/java/org/pitest/maven/AbstractPitMojo.java +++ b/pitest-maven/src/main/java/org/pitest/maven/AbstractPitMojo.java @@ -312,7 +312,7 @@ public class AbstractPitMojo extends AbstractMojo { /** * honours common skipTests flag in a maven run */ - @Parameter(defaultValue = "false") + @Parameter(property = "skipTests", defaultValue = "false") private boolean skipTests; /** From 195909dcf4250d22dfc8f69f27703c101f86ef93 Mon Sep 17 00:00:00 2001 From: Peter Date: Sun, 30 Jan 2022 19:21:09 +0100 Subject: [PATCH 2/2] #750 -DskipTests Flag should be honoured in a maven run without additional configuration - restored old test and added new IT test to verify if if -DskipTests works correctly --- .../src/test/java/org/pitest/PitMojoIT.java | 25 ++++---- .../resources/pit-skipTests-active/pom.xml | 59 +++++++++++++++++++ .../src/main/java/com/example/Covered.java | 13 ++++ .../src/main/java/com/example/NotCovered.java | 17 ++++++ .../test/java/com/example/AnotherTest.java | 21 +++++++ .../src/test/java/com/example/BadTest.java | 16 +++++ 6 files changed, 141 insertions(+), 10 deletions(-) create mode 100644 pitest-maven-verification/src/test/resources/pit-skipTests-active/pom.xml create mode 100644 pitest-maven-verification/src/test/resources/pit-skipTests-active/src/main/java/com/example/Covered.java create mode 100644 pitest-maven-verification/src/test/resources/pit-skipTests-active/src/main/java/com/example/NotCovered.java create mode 100644 pitest-maven-verification/src/test/resources/pit-skipTests-active/src/test/java/com/example/AnotherTest.java create mode 100644 pitest-maven-verification/src/test/resources/pit-skipTests-active/src/test/java/com/example/BadTest.java diff --git a/pitest-maven-verification/src/test/java/org/pitest/PitMojoIT.java b/pitest-maven-verification/src/test/java/org/pitest/PitMojoIT.java index 936a741f6..8a4b14233 100755 --- a/pitest-maven-verification/src/test/java/org/pitest/PitMojoIT.java +++ b/pitest-maven-verification/src/test/java/org/pitest/PitMojoIT.java @@ -19,11 +19,7 @@ import org.apache.maven.it.VerificationException; import org.apache.maven.it.Verifier; import org.apache.maven.it.util.ResourceExtractor; -import org.junit.After; -import org.junit.Before; -import org.junit.Ignore; -import org.junit.Rule; -import org.junit.Test; +import org.junit.*; import org.junit.rules.TemporaryFolder; import org.junit.rules.TestName; import org.pitest.support.DirectoriesOnlyWalker; @@ -38,10 +34,7 @@ import java.util.Properties; import static org.assertj.core.api.Assertions.assertThat; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; +import static org.junit.Assert.*; import static org.junit.Assume.assumeFalse; /** @@ -354,9 +347,21 @@ public void shouldCorrectlyHandleOverrides() throws Exception { buildFilePath(testDir, "target", "site", "pit-reports").exists()); } - @Test(expected = FileNotFoundException.class) + @Test public void shouldReadExclusionsFromSurefireConfig() throws Exception { File testDir = prepare("/pit-surefire-excludes"); + verifier.executeGoal("test"); + verifier.executeGoal("org.pitest:pitest-maven:mutationCoverage"); + + String actual = readResults(testDir); + assertThat(actual) + .contains( + "NotCovered.java"); + } + + @Test(expected = FileNotFoundException.class) + public void shouldNotExecuteWhenSkipTestsFlagActive() throws Exception { + File testDir = prepare("/pit-skipTests-active"); verifier.addCliOption("-DskipTests"); verifier.executeGoal("test"); verifier.executeGoal("org.pitest:pitest-maven:mutationCoverage"); diff --git a/pitest-maven-verification/src/test/resources/pit-skipTests-active/pom.xml b/pitest-maven-verification/src/test/resources/pit-skipTests-active/pom.xml new file mode 100644 index 000000000..d72cd1a51 --- /dev/null +++ b/pitest-maven-verification/src/test/resources/pit-skipTests-active/pom.xml @@ -0,0 +1,59 @@ + + 4.0.0 + com.example + junit-categories-check + jar + 1.0-SNAPSHOT + skipTests-active + + + junit + junit + 4.11 + test + + + + + + org.apache.maven.plugins + maven-compiler-plugin + 2.4 + + 1.7 + 1.7 + + + + org.apache.maven.plugins + maven-surefire-plugin + 2.18.1 + + + **/FailingTest.java + **/BadTest.java + + + + + org.pitest + pitest-maven + ${pit.version} + + true + + XML + + +CLASSLIMIT(limit[1]) + false + + NEGATE_CONDITIONALS + + true + + + + + + diff --git a/pitest-maven-verification/src/test/resources/pit-skipTests-active/src/main/java/com/example/Covered.java b/pitest-maven-verification/src/test/resources/pit-skipTests-active/src/main/java/com/example/Covered.java new file mode 100644 index 000000000..ea7b74b51 --- /dev/null +++ b/pitest-maven-verification/src/test/resources/pit-skipTests-active/src/main/java/com/example/Covered.java @@ -0,0 +1,13 @@ +package com.example; + +public class Covered { + + public static int someCode(int i) { + if ( i == 0 ) { + return 1; + } + + return 1; + } + +} diff --git a/pitest-maven-verification/src/test/resources/pit-skipTests-active/src/main/java/com/example/NotCovered.java b/pitest-maven-verification/src/test/resources/pit-skipTests-active/src/main/java/com/example/NotCovered.java new file mode 100644 index 000000000..ac93a193e --- /dev/null +++ b/pitest-maven-verification/src/test/resources/pit-skipTests-active/src/main/java/com/example/NotCovered.java @@ -0,0 +1,17 @@ +package com.example; + +public class NotCovered { + + public static int someCode(int i) { + if ( i == 0 ) { + return 1; + } + + if ( i == 2 ) { + return 42; + } + + return i; + } + +} diff --git a/pitest-maven-verification/src/test/resources/pit-skipTests-active/src/test/java/com/example/AnotherTest.java b/pitest-maven-verification/src/test/resources/pit-skipTests-active/src/test/java/com/example/AnotherTest.java new file mode 100644 index 000000000..7a5871b53 --- /dev/null +++ b/pitest-maven-verification/src/test/resources/pit-skipTests-active/src/test/java/com/example/AnotherTest.java @@ -0,0 +1,21 @@ +package com.example; + +import java.util.Arrays; +import java.util.Collection; +import org.junit.Test; + +import static org.junit.Assert.assertEquals; + +public class AnotherTest { + + @Test + public void aTest() { + assertEquals(1, Covered.someCode(0)); + } + + @Test + public void anotherTest() { + assertEquals(1, Covered.someCode(1)); + } + +} diff --git a/pitest-maven-verification/src/test/resources/pit-skipTests-active/src/test/java/com/example/BadTest.java b/pitest-maven-verification/src/test/resources/pit-skipTests-active/src/test/java/com/example/BadTest.java new file mode 100644 index 000000000..2d93c7688 --- /dev/null +++ b/pitest-maven-verification/src/test/resources/pit-skipTests-active/src/test/java/com/example/BadTest.java @@ -0,0 +1,16 @@ +package com.example; + +import java.util.Arrays; +import java.util.Collection; +import org.junit.Test; + +import static org.junit.Assert.assertEquals; + +public class BadTest { + + @Test + public void aTest() { + assertEquals(1, 2); + } + +}