Skip to content

Commit

Permalink
Merge pull request #972 from marwin1991/750_fix_skipTests_flag
Browse files Browse the repository at this point in the history
#750 -DskipTests Flag should be honoured in a maven run without additional configuration
  • Loading branch information
hcoles authored Jan 30, 2022
2 parents 1c2d301 + 195909d commit 0710e7b
Show file tree
Hide file tree
Showing 7 changed files with 142 additions and 13 deletions.
27 changes: 15 additions & 12 deletions pitest-maven-verification/src/test/java/org/pitest/PitMojoIT.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -32,15 +28,13 @@
import org.slf4j.LoggerFactory;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
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;

/**
Expand Down Expand Up @@ -356,14 +350,23 @@ public void shouldCorrectlyHandleOverrides() throws Exception {
@Test
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(
"<mutation detected='false' status='NO_COVERAGE' numberOfTestsRun='0'><sourceFile>NotCovered.java</sourceFile>");
.contains(
"<mutation detected='false' status='NO_COVERAGE' numberOfTestsRun='0'><sourceFile>NotCovered.java</sourceFile>");
}

@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");

readResults(testDir);
}

@Test
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.example</groupId>
<artifactId>junit-categories-check</artifactId>
<packaging>jar</packaging>
<version>1.0-SNAPSHOT</version>
<name>skipTests-active</name>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
<scope>test</scope>
</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.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.18.1</version>
<configuration>
<excludes>
<exclude>**/FailingTest.java</exclude>
<exclude>**/BadTest.java</exclude>
</excludes>
</configuration>
</plugin>
<plugin>
<groupId>org.pitest</groupId>
<artifactId>pitest-maven</artifactId>
<version>${pit.version}</version>
<configuration>
<exportLineCoverage>true</exportLineCoverage>
<outputFormats>
<value>XML</value>
</outputFormats>
<features>+CLASSLIMIT(limit[1])</features>
<timestampedReports>false</timestampedReports>
<mutators>
<mutator>NEGATE_CONDITIONALS</mutator>
</mutators>
<verbose>true</verbose>
</configuration>
</plugin>
</plugins>
</build>

</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.example;

public class Covered {

public static int someCode(int i) {
if ( i == 0 ) {
return 1;
}

return 1;
}

}
Original file line number Diff line number Diff line change
@@ -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;
}

}
Original file line number Diff line number Diff line change
@@ -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));
}

}
Original file line number Diff line number Diff line change
@@ -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);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/**
Expand Down

0 comments on commit 0710e7b

Please sign in to comment.