【问题标题】:Maven PITest Error "No plugin found for for prefix 'org.pitest' in the current project and in the plugin groups"Maven PITest 错误“在当前项目和插件组中找不到前缀 'org.pitest' 的插件”
【发布时间】:2023-03-04 09:01:01
【问题描述】:

我需要使用 PITest 进行突变测试,但我很难通过 Maven 安装它,当我尝试运行 PIT 来执行突变和测试用例时,我在 cmd 中收到此错误:

"在当前项目中没有找到前缀 'org.pitest' 的插件 并在插件组中”

有人可以帮我解决这个问题吗?

我的代码:

package com.mateus;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class Codigo {

    public boolean verify(String word){
        String regex = "^[a-zA-Z0-9_$]+$";
        Pattern pattern = Pattern.compile(regex);
        Matcher matcher = pattern.matcher(word);
        if(word.substring(0, 1).matches("[0-9]")){
            return false;
        }
        return matcher.matches();
    }

}

我的测试:

package com.mateus;

import static org.junit.Assert.*;

import org.junit.Test;

public class CodigoTest {
    Codigo c = new Codigo();
    @Test
    public void test() {
        assertEquals(true, c.verify("teste"));
    }
    @Test
    public void test2() {
        assertEquals(false, c.verify("1teste"));
    }
    @Test
    public void test3() {
        assertEquals(false, c.verify("tes@te"));
    }

}

pom.xml:

<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 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>com.mateus</groupId>
  <artifactId>MavenMutacao</artifactId>
  <version>0.0.1-SNAPSHOT</version>

    <dependencies>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.13-rc-1</version>
            <scope>test</scope>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.pitest</groupId>
                <artifactId>pitest-maven</artifactId>
                <version>1.4.3</version>
                <configuration>
                    <targetClasses>
                        <param>com.mateus*</param>
                    </targetClasses>
                    <targetTests>
                        <param>com.mateus*</param>
                    </targetTests>
                </configuration>
            </plugin>
        </plugins>
    </build>
</project>

这是出现在我的 cmd 上的错误:

C:\Users\mateu\eclipse-workspace\MavenMutacao>mvn org.pitest:pitest maven:mutationCoverage
[INFO] Scanning for projects...
Downloading from central: https://repo.maven.apache.org/maven2/org/apache/maven/plugins/maven-metadata.xml
Downloading from central: https://repo.maven.apache.org/maven2/org/codehaus/mojo/maven-metadata.xml
Downloaded from central: https://repo.maven.apache.org/maven2/org/codehaus/mojo/maven-metadata.xml (20 kB at 14 kB/s)
Downloaded from central: https://repo.maven.apache.org/maven2/org/apache/maven/plugins/maven-metadata.xml (14 kB at 9.3 kB/s)
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  2.303 s
[INFO] Finished at: 2019-11-19T16:39:59-02:00
[INFO] ------------------------------------------------------------------------
[ERROR] No plugin found for prefix 'org.pitest' in the current project and in the plugin groups [org.apache.maven.plugins, org.codehaus.mojo] available from the repositories [local (C:\Users\mateu\.m2\repository), central (https://repo.maven.apache.org/maven2)] -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/NoPluginFoundForPrefixException

【问题讨论】:

  • 您应该尝试使用mvn org.pitest:pitest-maven:mutationCoverage。我还会使用更新版本的 Pitest-maven 插件...1.4.10 ...
  • 我写了一篇文章解释如何使用变异测试和 PIT 可能对你有所帮助:pedrorijo.com/blog/intro-mutation/#mutation-testing-for-java
  • 如果你想了解如何使用 maven 多模块设置一个真实的实时项目,以这个为例:github.com/feedzai/feedzai-openml
  • 非常感谢@khmarbaise!它与该命令一起使用。还有一个问题,我执行了它并且一切正常,但是我的“目标”文件夹中没有文件可以查看结果的图形界面,知道为什么吗? @pedrorijo91
  • 应该有一个 html 文件,它通常在 target/site 中包含结果?你看过了吗?

标签: java maven unit-testing mutation-testing pitest


【解决方案1】:

你必须像这样使用插件。

<plugin>
    <groupId>org.pitest</groupId>
    <artifactId>pitest-maven</artifactId>
    <version>1.4.10</version>
    <configuration>
        <targetClasses>
            <param>com.mateus*</param>
        </targetClasses>
        <targetTests>
            <param>com.mateus*</param>
        </targetTests>
    </configuration>
</plugin>

EIDT: 而不是最新的,使用版本1.4.10 请参阅下面的参考链接。

https://pitest.org/quickstart/maven/

maven central 也有,可以查看这个链接。

https://search.maven.org/artifact/org.pitest/pitest-maven/1.4.10/maven-plugin

【讨论】:

  • 我只是按照你说的添加了依赖,但是出现了同样的错误,顺便说一句,最后一个版本是 1.4.10,我修复了它但保持不变,我应该用当前的 pom 编辑问题吗.xml 所以你可以看到它现在怎么样了?我真的需要尽快完成这项工作
  • 请发布完整的 pom.xml,以便我可以在最后尝试。
  • 我刚刚更新了答案,你现在可以试试。更新版本 1.4.10 代替 latest
  • @DebadattaMishra 使用 maven 插件作为依赖是完全错误的。问题只是在命令行上错误调用插件。
  • 你能告诉我在命令行上调用它的正确方法是什么吗? @khmarbaise
猜你喜欢
  • 2014-08-10
  • 2017-06-02
  • 2015-08-31
  • 1970-01-01
  • 2019-12-06
  • 2018-04-28
  • 2016-07-09
  • 1970-01-01
  • 2014-01-31
相关资源
最近更新 更多