Pitest 失败且未产生突变覆盖率

Pitest is failing and not generating mutation coverage

提问人:kyleryan1291 提问时间:6/29/2023 最后编辑:suhel mustoorkyleryan1291 更新时间:6/29/2023 访问量:348

问:

我正在尝试在我的项目中运行 Pitest,但一直收到此错误:

Failed to execute goal org.pitest:pitest-maven:1.14.2:mutationCoverage (default-cli) on project image-finder: Execution default-cli of goal org.pitest:pitest-maven:1.14.2:mutationCoverage failed: No mutations found. This probably means there is an issue with either the supplied classpath or filters.

我正在尝试使用以下命令从命令行运行 Pitest:mvn clean org.pitest:pitest-maven:mutationCoverage

幸运的是,我正在使用 IntelliJ,并且有一个可用的 IntelliJ Pitest 插件,当我运行它时,它确实可以工作。但是,我希望它也能从命令行工作。

我试过:

  • 设置 targetClasses 和 targetTests
    • 使用 、 指定目标类和测试类<param><targetTest><targetClass>
    • 指定的类如下:用于非测试类com.package.examples.*
    • 将测试类指定为: 和com.package.examples.*Testcom.package.examples.*
  • 未设置 targetClasses 和 targetTests
  • 将 Maven surefire 插件更新到最新版本
  • 没有在我的 Pitest 中设置任何配置pom.xml

我正在使用 JUnit 5,并在 Pitest 插件中包含必要的依赖项。我不确定为什么我总是收到这个错误。

我的 pom 文件目前:

<?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>com.github.kyleryxn</groupId>
    <artifactId>image-finder</artifactId>
    <version>1.0.0</version>
    <name>image-finder</name>
    <packaging>war</packaging>

    <properties>
        <jdk.version>17</jdk.version>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <maven.compiler.target>${jdk.version}</maven.compiler.target>
        <maven.compiler.source>${jdk.version}</maven.compiler.source>
        <spring.version>6.0.10</spring.version>
        <thymeleaf.version>3.1.1.RELEASE</thymeleaf.version>
        <mockito.version>5.4.0</mockito.version>
    </properties>

    <dependencies>
        <!-- Core libraries -->
        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-api</artifactId>
            <version>1.7.30</version>
        </dependency>
        <dependency>
            <groupId>ch.qos.logback</groupId>
            <artifactId>logback-classic</artifactId>
            <version>1.2.9</version>
        </dependency>
        <dependency>
            <groupId>commons-io</groupId>
            <artifactId>commons-io</artifactId>
            <version>2.11.0</version>
        </dependency>
        <dependency>
            <groupId>com.google.code.gson</groupId>
            <artifactId>gson</artifactId>
            <version>2.8.9</version>
        </dependency>
        <dependency>
            <groupId>org.jsoup</groupId>
            <artifactId>jsoup</artifactId>
            <version>1.15.3</version>
        </dependency>

        <!-- Database libraries -->


        <!-- Servlet libraries -->
        <dependency>
            <groupId>jakarta.persistence</groupId>
            <artifactId>jakarta.persistence-api</artifactId>
            <version>3.1.0</version>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>jakarta.servlet</groupId>
            <artifactId>jakarta.servlet-api</artifactId>
            <version>6.0.0</version>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>jakarta.websocket</groupId>
            <artifactId>jakarta.websocket-api</artifactId>
            <version>2.1.0</version>
            <scope>provided</scope>
        </dependency>

        <!-- Web framework libraries -->
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-webmvc</artifactId>
            <version>${spring.version}</version>
        </dependency>
        <dependency>
            <groupId>org.thymeleaf</groupId>
            <artifactId>thymeleaf</artifactId>
            <version>${thymeleaf.version}</version>
        </dependency>
        <dependency>
            <groupId>org.thymeleaf</groupId>
            <artifactId>thymeleaf-spring6</artifactId>
            <version>${thymeleaf.version}</version>
        </dependency>

        <!-- Test libraries -->
        <dependency>
            <groupId>org.junit.jupiter</groupId>
            <artifactId>junit-jupiter</artifactId>
            <version>5.9.3</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>pl.pragmatists</groupId>
            <artifactId>JUnitParams</artifactId>
            <version>1.1.1</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.mockito</groupId>
            <artifactId>mockito-core</artifactId>
            <version>${mockito.version}</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.mockito</groupId>
            <artifactId>mockito-junit-jupiter</artifactId>
            <version>${mockito.version}</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-test</artifactId>
            <version>${spring.version}</version>
            <scope>test</scope>
        </dependency>
    </dependencies>

    <build>
        <finalName>image-finder</finalName>
        <resources>
            <resource>
                <directory>src/main/resources</directory>
                <includes>
                    <include>**/*</include>
                </includes>
            </resource>
        </resources>
        <testResources>
            <testResource>
                <directory>src/test/resources</directory>
                <includes>
                    <include>**/*.json</include>
                </includes>
            </testResource>
        </testResources>

        <!-- Update default Maven plugin versions -->
        <pluginManagement>
            <plugins>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-clean-plugin</artifactId>
                    <version>3.1.0</version>
                </plugin>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-compiler-plugin</artifactId>
                    <version>3.7.0</version>
                </plugin>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-dependency-plugin</artifactId>
                    <version>3.1.1</version>
                </plugin>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-deploy-plugin</artifactId>
                    <version>2.8.2</version>
                </plugin>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-install-plugin</artifactId>
                    <version>2.5.2</version>
                </plugin>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-resources-plugin</artifactId>
                    <version>3.1.0</version>
                </plugin>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-surefire-plugin</artifactId>
                    <version>3.1.2</version>
                </plugin>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-war-plugin</artifactId>
                    <version>3.2.2</version>
                </plugin>
            </plugins>
        </pluginManagement>

        <plugins>
            <plugin>
                <groupId>org.pitest</groupId>
                <artifactId>pitest-maven</artifactId>
                <version>1.14.2</version>
                <dependencies>
                    <dependency>
                        <groupId>org.pitest</groupId>
                        <artifactId>pitest-junit5-plugin</artifactId>
                        <version>1.2.0</version>
                    </dependency>
                </dependencies>
            </plugin>
        </plugins>
    </build>
</project>

任何帮助将不胜感激

java maven pom.xml pitest

评论

1赞 khmarbaise 6/29/2023
首先,您通过以下方式间接混合 junit jupiter 和 junit 4 ...此外,您还没有定义,问题也是您的所有测试是否在平时正确执行?而且非常重要的通过无法工作,因为突变测试需要执行测试,这意味着您必须使用...pl.pragmatistsjunit-jupiter-enginemvn clean testmvn clean org.pitest:pitest-maven:mutationCoveragemvn clean test org.pitest:pitest-maven:mutationCoverage
0赞 kyleryan1291 7/10/2023
我正在使用 JUnit 5,我使用的依赖项包含所有 JUnit 5 依赖项(因此是我的 Pitest 插件的插件),因此我不需要定义引擎。但是,尽管如此,我还是发现了这个问题,你是对的,它与Pitest配置和测试有关

答: 暂无答案