Skip to content

Commit

Permalink
#750 -DskipTests Flag should be honoured in a maven run without addit…
Browse files Browse the repository at this point in the history
…ional configuration - restored old test and added new IT test to verify if if -DskipTests works correctly
  • Loading branch information
marwin1991 committed Jan 30, 2022
1 parent 7b19bf0 commit 195909d
Show file tree
Hide file tree
Showing 6 changed files with 141 additions and 10 deletions.
25 changes: 15 additions & 10 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 @@ -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;

/**
Expand Down Expand Up @@ -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(
"<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");
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);
}

}

0 comments on commit 195909d

Please sign in to comment.