Pitest can't detect class of test
Asked Answered
C

5

4

i have problem with my configuration of maven and pitest.

Pitest generation mutation is ok but he can't see my class of test ..

if you have any solution :D


I have main source like that /src/main/java/com.plugin..... .java

I have test source like that /src/test/java/com.plugin.... .java


pom.xml config :

<plugin>
            <groupId>org.pitest</groupId>
            <artifactId>pitest-maven</artifactId>
            <version>1.1.9</version>
            <configuration>
                <targetClasses>
                    <param>com.plugin.business.centre*</param>
                </targetClasses>
                <targetTests>
                    <param> com.plugin.business.centre*</param>
                </targetTests>
            </configuration>
    </plugin>

in < targetTests > .. he know only my source class with autocomplete and not my test class.


[INFO] --- pitest-maven:1.1.9:mutationCoverage (default-cli) @ Polux ---
[INFO] Found plugin : Default csv report plugin
[INFO] Found plugin : Default xml report plugin
[INFO] Found plugin : Default html report plugin
[INFO] Found plugin : Default limit mutations plugin
[INFO] Found shared classpath plugin : Default mutation engine
[INFO] Adding org.pitest:pitest to SUT classpath
[INFO] Mutating from /Users/Mods/Documents/*****/target/classes
08:35:36 PIT >> INFO : Verbose logging is disabled. If you encounter an problem please enable it before reporting an issue.
08:35:36 PIT >> INFO : MINION : objc[677]: Class JavaLaunchHelper is implemented in both /Library/Java/JavaVirtualMachines/jdk1.8.0_65.jdk/Contents/Home/jre/bin/java and /Library/Java/JavaVirtualMachines/jdk1.8.0_65.jdk/Contents/Home/jre/lib/libinstrument.dylib. One of the two will be us
08:35:36 PIT >> INFO : MINION : ed. Which one is undefined.

08:35:37 PIT >> INFO : Sending 0 test classes to minion
08:35:37 PIT >> INFO : Sent tests to minion
08:35:37 PIT >> INFO : MINION : 08:35:37 PIT >> INFO : Checking environment

08:35:37 PIT >> INFO : MINION : 08:35:37 PIT >> INFO : Found  0 tests

08:35:37 PIT >> INFO : MINION : 08:35:37 PIT >> INFO : Dependency analysis reduced number of potential tests by 0

08:35:37 PIT >> INFO : MINION : 08:35:37 PIT >> INFO : 0 tests received

08:35:37 PIT >> INFO : Calculated coverage in 0 seconds.
08:35:37 PIT >> INFO : Created  20 mutation test units
Croquet answered 18/2, 2016 at 8:6 Comment(3)
Does maven find your tests, when you run mvn test? Also, try <verbose>true</verbose> in your configuration.Sanatory
Have you really a folder which is called com.plugin ? Your folder should be named like 'src/main/java/com/plugin/..' ...Be aware of the difference between java package name and the mapped folder structure...Then
mvn test work fine :) i have previous configuration of "evosuite" in my pom.xml, i have delete them and now pitest found correctly my test class. <3Croquet
E
8

I need to add the junit5 plugin as a dependency (as I'm using JUnit 5).

<plugin>
    <groupId>org.pitest</groupId>
    <artifactId>pitest-maven</artifactId>
    <version>1.4.5</version>
    <dependencies>
        <dependency>
            <groupId>org.pitest</groupId>
            <artifactId>pitest-junit5-plugin</artifactId>
            <version>0.8</version>
        </dependency>
    </dependencies>
    <configuration>
        ...
    </configuration>
</plugin>
Elephantiasis answered 1/3, 2019 at 19:26 Comment(0)
A
7

For people reaching this question with the same problem:

I was facing the same issue and I fixed it by running mvn test before Pitest.

Pitest somehow needs those tests to be executed at least one to find them.

Aerostatics answered 22/7, 2016 at 19:10 Comment(0)
C
1

It was not working as we migrated from Junit4 to Junit5. There is no support to Junit5 directly. The solution is to use the plugin from pitest for Junit5 Refer https://github.com/pitest/pitest-junit5-plugin

plugins {
    id 'java'
    id 'info.solidsoft.pitest' version '1.5.1'
}

pitest {
    //adds dependency to org.pitest:pitest-junit5-plugin and sets "testPlugin" to "junit5"
    junit5PluginVersion = '0.12'
    // ...
}
Cero answered 2/11, 2020 at 12:21 Comment(0)
F
0

My tests weren't detected because I used Java's built-in assert, e.g.:

assert 1 + 2 == 3;

When I changed it to JUnit's:

import static org.junit.Assert.assertEquals;

assertEquals(1 + 2, 3);

PITest works as expected. I didn't dig deeper why it works this way.

Fleming answered 15/9, 2020 at 10:22 Comment(0)
G
-1

Pitest can not find testPlugin automatically, set it manually:

for maven:

<testPlugin>
    <value>junit5</value>
</testPlugin>

for gradle:

pitest {
    testPlugin = "junit5" //or another test plugin
    ...
}
Gustafson answered 9/12, 2018 at 4:45 Comment(3)
The maven configuration did not work for me. It gave an error.Virendra
Unable to parse configuration of mojo org.pitest:pitest-maven:1.7.3:mutationCoverage: Basic element 'testPlugin' must not contain child elementsFourflusher
Worked with <testPlugin>junit5</testPlugin> for me.Canto

© 2022 - 2024 — McMap. All rights reserved.