0

I am trying to integrate PIT testing into my project.

This is my pom.xml file.

pom.xml

<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/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>

  <groupId>com2.com3.app</groupId>
  <artifactId>team-10</artifactId>
  <version>1.0-SNAPSHOT</version>
  <build>
    <sourceDirectory>src</sourceDirectory>
    <directory>target</directory>
    <testSourceDirectory>test</testSourceDirectory>
    <testOutputDirectory>target/classes</testOutputDirectory>
    <plugins>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-compiler-plugin</artifactId>
        <configuration>
          <source>11</source>
          <target>11</target>
        </configuration>
      </plugin>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-surefire-plugin</artifactId>
        <version>2.19.1</version>
        <dependencies>
          <dependency>
            <groupId>org.junit.platform</groupId>
            <artifactId>junit-platform-surefire-provider</artifactId>
            <version>1.0.0</version>
          </dependency>
          <dependency>
            <groupId>org.junit.jupiter</groupId>
            <artifactId>junit-jupiter-engine</artifactId>
            <version>5.0.0</version>
          </dependency>
        </dependencies>
      </plugin>
      <plugin>
        <groupId>org.pitest</groupId>
        <artifactId>pitest-maven</artifactId>
        <version>1.4.6</version>
        <configuration>
          <targetClasses>
            <param>com1.com2.com3.impl.app.LsApplication</param>
          </targetClasses>
          <targetTests>
            <param>com1.com2.com3.impl.app.LsApplicationTest</param>
          </targetTests>
        </configuration>
      </plugin>
    </plugins>
  </build>

  <properties>
    <maven.compiler.source>1.8</maven.compiler.source>
    <maven.compiler.target>1.8</maven.compiler.target>
    <myTestSourceDirectory>test</myTestSourceDirectory>
  </properties>

  <dependencies>
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>4.12</version>
    </dependency>
    <dependency>
      <groupId>org.slf4j</groupId>
      <artifactId>slf4j-simple</artifactId>
      <version>1.7.3</version>
    </dependency>
    <dependency>
      <groupId>org.junit.jupiter</groupId>
      <artifactId>junit-jupiter-api</artifactId>
      <version>5.7.0</version>
    </dependency>
    <dependency>
      <groupId>org.pitest</groupId>
      <artifactId>pitest-junit5-plugin</artifactId>
      <version>0.7</version>
    </dependency>
  </dependencies>
</project>

My project is using Maven but it is currently not following the default structure. The source code is stored at src/com1.com2.com3 while the test code is stored at test/com1.com2.com3

I ran mvn clean install, which runs through all the Test files I have created using surefire, but all of them result in Failure.

I then proceeded to ran mvn org.pitest:pitest-maven:mutationCoverage which produces the following output, that passes in 2 class files, one being a source and 1 being the class file. However none of the tests are detected. The tests are working fine running under JUnit, what could I be missing out here? Let me know if more information is needed.

[INFO] Found plugin : Default csv report plugin
[INFO] Found plugin : Default xml report plugin
[INFO] Found plugin : Default html report plugin
[INFO] Found plugin : Static initializer code detector plugin
[INFO] Found plugin : Static initializer filter plugin
[INFO] Found plugin : Excluded annotations plugin
[INFO] Found plugin : Inlined finally block filter plugin
[INFO] Found plugin : Try with resources filter
[INFO] Found plugin : Implicit null check filter
[INFO] Found plugin : For each loop filter
[INFO] Found plugin : Logging calls filter
[INFO] Found plugin : Infinite for loop filter
[INFO] Found plugin : Long running iterator loop filter
[INFO] Found plugin : For loop counter filter
[INFO] Found plugin : Kotlin junk mutations filter
[INFO] Found plugin : Max mutations per class limit
[INFO] Found plugin : Equals shortcut equivalent mutant filter
[INFO] Found plugin : Trivial return vals equivalence filter
[INFO] Found plugin : Mutant export plugin
[INFO] Found shared classpath plugin : Default mutation engine
[INFO] Found shared classpath plugin : JUnit plugin
[INFO] Found shared classpath plugin : TestNG plugin
[INFO] Adding org.pitest:pitest to SUT classpath
[INFO] Mutating from /Users/prashin/target/classes
3:10:40 pm PIT >> INFO : Verbose logging is disabled. If you encounter a problem, please enable it before reporting an issue.
3:10:40 pm PIT >> INFO : Sending 2 test classes to minion
3:10:40 pm PIT >> INFO : Sent tests to minion
3:10:40 pm PIT >> INFO : MINION : 3:10:40 pm PIT >> INFO : Checking environment

3:10:40 pm PIT >> INFO : MINION : 3:10:40 pm PIT >> INFO : Found  0 tests

3:10:40 pm PIT >> INFO : MINION : 3:10:40 pm PIT >> INFO : Dependency analysis reduced number of potential tests by 0

3:10:40 pm PIT >> INFO : MINION : 3:10:40 pm PIT >> INFO : 0 tests received

3:10:40 pm PIT >> INFO : Calculated coverage in 0 seconds.
3:10:40 pm PIT >> INFO : Created  1 mutation test units                                                                                                                    /3:10:41 pm PIT >> INFO : Completed in 1 seconds
================================================================================
- Mutators
================================================================================
> org.pitest.mutationtest.engine.gregor.mutators.ConditionalsBoundaryMutator
>> Generated 8 Killed 0 (0%)
> KILLED 0 SURVIVED 0 TIMED_OUT 0 NON_VIABLE 0 
> MEMORY_ERROR 0 NOT_STARTED 0 STARTED 0 RUN_ERROR 0 
> NO_COVERAGE 8 
--------------------------------------------------------------------------------
> org.pitest.mutationtest.engine.gregor.mutators.IncrementsMutator
>> Generated 3 Killed 0 (0%)
> KILLED 0 SURVIVED 0 TIMED_OUT 0 NON_VIABLE 0 
> MEMORY_ERROR 0 NOT_STARTED 0 STARTED 0 RUN_ERROR 0 
> NO_COVERAGE 3 
--------------------------------------------------------------------------------
> org.pitest.mutationtest.engine.gregor.mutators.VoidMethodCallMutator
>> Generated 10 Killed 0 (0%)
> KILLED 0 SURVIVED 0 TIMED_OUT 0 NON_VIABLE 0 
> MEMORY_ERROR 0 NOT_STARTED 0 STARTED 0 RUN_ERROR 0 
> NO_COVERAGE 10 
--------------------------------------------------------------------------------
> org.pitest.mutationtest.engine.gregor.mutators.ReturnValsMutator
>> Generated 25 Killed 0 (0%)
> KILLED 0 SURVIVED 0 TIMED_OUT 0 NON_VIABLE 0 
> MEMORY_ERROR 0 NOT_STARTED 0 STARTED 0 RUN_ERROR 0 
> NO_COVERAGE 25 
--------------------------------------------------------------------------------
> org.pitest.mutationtest.engine.gregor.mutators.MathMutator
>> Generated 5 Killed 0 (0%)
> KILLED 0 SURVIVED 0 TIMED_OUT 0 NON_VIABLE 0 
> MEMORY_ERROR 0 NOT_STARTED 0 STARTED 0 RUN_ERROR 0 
> NO_COVERAGE 5 
--------------------------------------------------------------------------------
> org.pitest.mutationtest.engine.gregor.mutators.NegateConditionalsMutator
>> Generated 51 Killed 0 (0%)
> KILLED 0 SURVIVED 0 TIMED_OUT 0 NON_VIABLE 0 
> MEMORY_ERROR 0 NOT_STARTED 0 STARTED 0 RUN_ERROR 0 
> NO_COVERAGE 51 
--------------------------------------------------------------------------------
================================================================================
- Timings
================================================================================
> scan classpath : < 1 second
> coverage and dependency analysis : < 1 second
> build mutation tests : < 1 second
> run mutation analysis : < 1 second
--------------------------------------------------------------------------------
> Total  : < 1 second
--------------------------------------------------------------------------------
================================================================================
- Statistics
================================================================================
>> Generated 102 mutations Killed 0 (0%)
>> Ran 0 tests (0 tests per mutation)
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  2.249 s
[INFO] Finished at: 2021-03-21T15:10:41+08:00
[INFO] ------------------------------------------------------------------------






 
Prashin Jeevaganth
  • 1,223
  • 1
  • 18
  • 42

2 Answers2

1

First why are you changing the default like source Directory etc. follow conventions it's easier. so remove the following:

<sourceDirectory>src</sourceDirectory>
<directory>target</directory>
<testSourceDirectory>test</testSourceDirectory>
<testOutputDirectory>target/classes</testOutputDirectory>

and change the directory layout of your project accordingly to the maven conventions.

Second if you use junit jupiter you have to use at least surefire 2.22.2 better more recent versions (3.0.0-M5).

Furthermore you using junit jupiter 5.0.0 which is about 3 years old... you should go to the most recent one (5.7.1) and you are defining manually the junit-platform-surefire-provider which shouldn't be done anymore (long time)...

The pitest-maven version you are using is very old (most recent 1.6.4) and finally pitest-junit5-plugin should be defined as dependency of the pitest-maven-plugin where the version 0.14 is out in the meantime.

You can take a look at an example project like this: https://github.com/khmarbaise/kata-fraction/blob/master/pom.xml

Also you are mixing different concepts:

The configuration for the maven-compiler-plugin:

<configuration>
  <source>11</source>
  <target>11</target>
</configuration>

and the property based approach:

<properties>
  <maven.compiler.source>1.8</maven.compiler.source>
  <maven.compiler.target>1.8</maven.compiler.target>
  <myTestSourceDirectory>test</myTestSourceDirectory>
</properties>

So the final question is: JDK 8 or JDK11?

If you use JDK11 you should setup only of those options and not both and second you could check if it would be better to use --release 11 via (<maven.compiler.release>11</maven.compiler.release> property based)..

Finally I saw that you have a dependency:

<dependency>
  <groupId>junit</groupId>
  <artifactId>junit</artifactId>
  <version>4.12</version>
</dependency>

Does that mean you are using JUnit 4 based unit tests? If so you have to add the junit-vintage-engine so you could run your JUnit 4 based tests via JUnit Jupiter. I strongly recommend to migrate all JUnit 4 based tests to JUnit Jupiter and afterwards remove the junit 4 dependency.

khmarbaise
  • 92,914
  • 28
  • 189
  • 235
  • Hi, thank you for your long answer. I think you can tell I am very new to Maven and I have lots of issues with setting up. To answer some of your queries, the original project is not of Maven structure, somehow my friend added a pom.xml(using Junit4) inside but it wasn’t configured to the default structure until I took over. I have constantly been googling for solutions based solely on my error messages and I just kept adding on the dependencies, just to silence the error messages. I think the posts I read are not very updated, which is why the versions of the libraries are quite old. – Prashin Jeevaganth Mar 21 '21 at 09:00
  • We’re actually running the application via IntelliJ’s Junit5 classpath manually until we had to integrate PIT, definitely we will prefer the use of more recent and stable builds which are using Junit5 and Jdk11. What would your best advice be for my situation? – Prashin Jeevaganth Mar 21 '21 at 09:00
  • First change the directory structure and follow the conventions. Second upgrade to more recent versions of plugins/tools... and check each step on plain command line... – khmarbaise Mar 21 '21 at 10:17
1

We have very detailed documentation. It contains examples and also links to our integration tests on GitHub. Please open this link in your browser https://maven.apache.org/surefire/maven-surefire-plugin/examples/junit-platform.html and feel free to ask questions if something is not clear. We are keen to answer the questions.

tibor17
  • 1,043
  • 6
  • 9