Maven + 突变测试

问题描述

我遵循了本教程: https://pitest.org/quickstart/maven/

jar 文件无法打开。我有 Java 版本 8 更新 291。

我试过了:

$ java -jar pitest-maven-1.6.7.jar
no main manifest attribute,in pitest-maven-1.6.7.jar

我遵循了本教程: https://www.baeldung.com/java-mutation-testing-with-pitest

我第 5 步对我不起作用:mvn 命令存在

mvn command is not recognized as an internal or external command 'mvn' is not recognized as an internal or external command,

mvn' is not recognized as an internal or external command

Apache Maven install "'mvn' not recognized as an internal or external command" after setting OS environmental variables?

我没有通往 Maven 的路径。

我也尝试过这些教程,它们缺少关键的重要步骤:

https://medium.com/@mailshine/mutation-testing-can-unit-test-coverage-survive-a9f9b64e6fbf

https://dzone.com/articles/mutation-testing-covering-your-code-with-right-tes-1

这些教程太长了,我可能会很快在 stackoverflow 上得到答案:

https://www.youtube.com/watch?v=88fDcPurp-Y&ab_channel=SpringDeveloper

https://www.youtube.com/watch?v=DSv2vpvD-ds&ab_channel=GreenLearner

解决方法

如何在 maven 中实际设置突变测试

基本上...遵循本教程:https://pitest.org/quickstart/maven/

跳过教程中的安装部分

下载 apache-maven-3.8.1 [或最新版本]

通过命令行将下载的文件添加到您的路径:

set PATH=%PATH%;C:\Program Files\apache-maven-3.8.1\bin

这是您要添加的实际插件:

<plugin>
    <groupId>org.pitest</groupId>
    <artifactId>pitest-maven</artifactId>
    <version>1.6.7</version>
    <dependencies>
        <dependency>
            <groupId>org.pitest</groupId>
            <artifactId>pitest-junit5-plugin</artifactId>
            <version>0.14</version>
        </dependency>
    </dependencies>
    <configuration>
        <targetClasses>
            <param>com.my.project.*</param>
        </targetClasses>
        <targetTests>
            <param>com.my.project*</param>
        </targetTests>
    </configuration>
</plugin>

您可以替换版本和 my.project 但确保 my.project 有 .*

像这样:

com.your.project.*

不是这个:

com.your.project

之后,你需要这个依赖:

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

从这里开始,教程非常棒。您可以通过在命令行中运行它来继续:

mvn org.pitest:pitest-maven:mutationCoverage

然后你打开文件夹等等