Pitest can't detect class of test

后端 未结 5 774
星月不相逢
星月不相逢 2020-12-22 08:05

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

相关标签:
5条回答
  • 2020-12-22 08:25

    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>
    
    0 讨论(0)
  • 2020-12-22 08:25

    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'
        // ...
    }
    
    0 讨论(0)
  • 2020-12-22 08:30

    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
        ...
    }
    
    0 讨论(0)
  • 2020-12-22 08:32

    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.

    0 讨论(0)
  • 2020-12-22 08:41

    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.

    0 讨论(0)
提交回复
热议问题