坑报告突变覆盖率 尝试运行覆盖率时出现问题

Pit report mutation coverage Issue when trying to run coverage

提问人:Mohammad 提问时间:5/3/2023 最后编辑:zforgoMohammad 更新时间:5/7/2023 访问量:284

问:

enter image description here

我在尝试运行突变覆盖率
或在调试模式下收到此错误。
mvn org.pitest:pitest-maven:mutationCoveragemvn verify -PPIT -X

Error:
Execution pit-report of goal org.pitest:pitest-maven:1.13.0:mutationCoverage failed: Coverage generation minion exited abnormally! (UNKNOWN_ERROR)

查看了一堆其他类似的问题或博客,但似乎没有什么可以解决此错误。

我添加和取出了很多东西,希望能有所作为。pom.xml

我将添加与此问题相关的 pom 片段。

pom.xml:

<project>
    <properties>
        <maven.compiler.source>1.8</maven.compiler.source>
        <maven.compiler.target>1.8</maven.compiler.target>
        <junit.version>4.9</junit.version>
        <pitest.version>1.4.3</pitest.version>
    </properties>
    <dependencies>
        <dependency>
            <groupId>org.pitest</groupId>
            <artifactId>pitest-junit5-plugin</artifactId>
            <version>0.14</version>
        </dependency>
        <dependency>
            <groupId>org.junit.jupiter</groupId>
            <artifactId>junit-jupiter-engine</artifactId>
            <version>5.7.2</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.9</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-actuator-autoconfigure</artifactId>
            <version>3.0.6</version>
        </dependency>
    </dependencies>
    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-surefire-plugin</artifactId>
                <version>3.0.0-M1</version>
            </plugin>

            <plugin>
                <groupId>org.pitest</groupId>
                <artifactId>pitest-maven</artifactId>
                <version>${pitest.version}</version>

                <executions>
                    <execution>
                        <id>pit-report</id>
                        <phase>test</phase>
                        <goals>
                            <goal>mutationCoverage</goal>
                        </goals>
                    </execution>
                </executions>

                <!-- https://github.com/hcoles/pitest/issues/284 -->
                <!-- Need this to support JUnit 5 -->
                <dependencies>
                    <dependency>
                        <groupId>org.pitest</groupId>
                        <artifactId>pitest-junit5-plugin</artifactId>
                        <version>0.8</version>
                    </dependency>
                </dependencies>
                <configuration>
                    <targetClasses>
                        <param>com.mkyong.examples.*</param>
                    </targetClasses>
                    <targetTests>
                        <param>com.mkyong.examples.*</param>
                    </targetTests>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.pitest</groupId>
                <artifactId>pitest-maven</artifactId>
                <version>1.13.0</version>
                <configuration>
                    <targetClasses>
                        <param>com.your.package.root.want.to.mutate*</param>
                    </targetClasses>
                    <targetTests>
                        <param>com.your.package.root*</param>
                    </targetTests>
                </configuration>
            </plugin>
        </plugins>
    </build>
</project>
Maven JUNIT 突变 pitest

评论

0赞 khmarbaise 5/3/2023
首先将 pitest-maven 升级到最新版本 1.13.0,并在 pitest-maven 的配置中定义 pitest-junit5-plugin(最新版本以及 1.1.2)......此外,您已经在 pom 文件中定义了两次 pitest-maven(只做一次)......此外,使用最新版本的 maven-surefire-plugin(3.0.0) 更重要的是,如果您喜欢使用 spring-boot 3.X,您必须至少使用 JDK17...并升级您的 junit-jupiter 版本...到最新版本,如果您真的需要使用 JUnit,您也应该使用最新版本......
0赞 khmarbaise 5/3/2023
如果您需要运行基于 JUnit 4 的测试,则必须添加 junit-vintage-engine...
0赞 khmarbaise 5/3/2023
将插件定义为依赖项是完全错误的......

答:

0赞 khmarbaise 5/3/2023 #1

我做了一些使用spring-boot版本3.0.6的示例设置。还需要正确定义插件,如下所示...此外,您需要的依赖项.

正如我所提到的,如果你真的需要使用 JUnit 4,你必须添加 junit jupiter-vintage 引擎作为依赖项。

https://central.sonatype.com/search?q=pitest-maven

对于 Spring Boot 3.X,您必须使用 JDK17+...

<?xml version="1.0" encoding="UTF-8"?>
<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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>xyz.test</groupId>
  <artifactId>abc</artifactId>
  <version>0.0.1-SNAPSHOT</version>

  <properties>
    <maven.compiler.release>17</maven.compiler.release>
    <spring.boot.version>3.0.6</spring.boot.version>
  </properties>

  <dependencyManagement>
    <dependencies>
      <dependency>
        <groupId>org.junit</groupId>
        <artifactId>junit-bom</artifactId>
        <version>5.9.3</version>
        <type>pom</type>
        <scope>import</scope>
      </dependency>
      <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-dependencies</artifactId>
        <version>${spring.boot.version}</version>
        <scope>import</scope>
        <type>pom</type>
      </dependency>
    </dependencies>
  </dependencyManagement>
  <dependencies>
    <dependency>
      <groupId>org.junit.jupiter</groupId>
      <artifactId>junit-jupiter-engine</artifactId>
      <scope>test</scope>
    </dependency>
    <dependency>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-actuator-autoconfigure</artifactId>
    </dependency>
  </dependencies>

  <build>
    <plugins>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-clean-plugin</artifactId>
        <version>3.2.0</version>
      </plugin>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-jar-plugin</artifactId>
        <version>3.3.0</version>
      </plugin>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-install-plugin</artifactId>
        <version>3.1.1</version>
      </plugin>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-deploy-plugin</artifactId>
        <version>3.1.1</version>
      </plugin>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-resources-plugin</artifactId>
        <version>3.3.1</version>
      </plugin>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-compiler-plugin</artifactId>
        <version>3.11.0</version>
        <configuration>
          <compilerArgs>
            <arg>-Xlint:all</arg>
            <arg>-Xlint:-processing</arg>
            <arg>-parameters</arg>
          </compilerArgs>
        </configuration>
      </plugin>
      <plugin>
        <artifactId>maven-surefire-plugin</artifactId>
        <version>3.0.0</version>
      </plugin>
      <plugin>
        <artifactId>maven-failsafe-plugin</artifactId>
        <version>3.0.0</version>
      </plugin>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-dependency-plugin</artifactId>
        <version>3.5.0</version>
      </plugin>
      <plugin>
        <groupId>org.jacoco</groupId>
        <artifactId>jacoco-maven-plugin</artifactId>
        <version>0.8.10</version>
      </plugin>
      <plugin>
        <groupId>org.sonarsource.scanner.maven</groupId>
        <artifactId>sonar-maven-plugin</artifactId>
        <version>3.9.1.2184</version>
      </plugin>
      <plugin>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-maven-plugin</artifactId>
        <version>${spring.boot.version}</version>
      </plugin>
      <plugin>
        <groupId>org.codehaus.mojo</groupId>
        <artifactId>versions-maven-plugin</artifactId>
        <version>2.15.0</version>
      </plugin>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-enforer-plugin</artifactId>
        <version>3.10</version>
      </plugin>
      <plugin>
        <groupId>org.pitest</groupId>
        <artifactId>pitest-maven</artifactId>
        <version>1.13.1</version>
        <dependencies>
          <dependency>
            <groupId>org.pitest</groupId>
            <artifactId>pitest-junit5-plugin</artifactId>
            <version>1.1.2</version>
          </dependency>
        </dependencies>
        <executions>
          <execution>
            <phase>test</phase>
            <goals>
              <goal>mutationCoverage</goal>
            </goals>
            <configuration>
              <targetClasses>
                <param>com.your.package.root.want.to.mutate*</param>
              </targetClasses>
              <targetTests>
                <param>com.your.package.root*</param>
              </targetTests>
            </configuration>
          </execution>
        </executions>
      </plugin>
    </plugins>
  </build>

</project>

评论

1赞 Mohammad 5/3/2023
感谢您的回答。我尝试了你所说的一些组合并让它起作用