0

I need to make a mutation test with PITest, but I'm having a hard time trying to install it via Maven, when I try to run PIT to execute mutations and the test case, I receive this error in the cmd:

"No plugin found for for prefix 'org.pitest' in the current project and in the plugin groups"

Can someone help me solve this problem, please?

My code:

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();
    }

}

My Tests:

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>

This is the error that appears on my 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
Mateus99
  • 119
  • 1
  • 2
  • 9
  • You should try to use `mvn org.pitest:pitest-maven:mutationCoverage`. I would also use a more recent version of the pitest-maven plugin...1.4.10 ... – khmarbaise Nov 19 '19 at 21:19
  • I wrote an article explaining how to use mutation test and PIT that may help you: https://pedrorijo.com/blog/intro-mutation/#mutation-testing-for-java – pedrorijo91 Nov 20 '19 at 00:56
  • and if you want to see how to setup a real live project, with maven multi modules, take as an example this one: https://github.com/feedzai/feedzai-openml – pedrorijo91 Nov 20 '19 at 00:58
  • thank you very much, @khmarbaise!! It worked with that command. Just one more question, I executed it and all worked just fine, but there is no file in my "target" folder to see a graphic interface of the results, any idea why? @pedrorijo91 – Mateus99 Nov 20 '19 at 15:37
  • There should be somewhere an html file which contains the result usually in target/site ? Have you taken a look into it? – khmarbaise Nov 20 '19 at 16:28
  • There is a folder "target" but there is nothing inside it, not even an html file. Maybe it is because all the mutants were killed? Or should the html be generated anyway? – Mateus99 Nov 20 '19 at 17:06

1 Answers1

1

You have to use the plugin like this.

<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: Instead of latest, use the version 1.4.10 See the reference below link.

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

It is also available in maven central, you can check this link.

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

PythonLearner
  • 1,416
  • 7
  • 22
  • I just added the dependency as you said, but the same error appears, btw, the last version is 1.4.10, I fixed it but stays the same, should I edit the question with the current pom.xml so you can see how it is now? I really need to make this work as soon as possible – Mateus99 Nov 19 '19 at 19:37
  • Please post the complete pom.xml so that I can try at my end. – PythonLearner Nov 19 '19 at 19:39
  • I just updated the answer, you can try now. Update the version `1.4.10` in place of latest – PythonLearner Nov 19 '19 at 19:44
  • @DebadattaMishra Using maven plugin as a dependency is simply wrong. The issue is simply the wrong calling of the plugin on command line. – khmarbaise Nov 19 '19 at 21:25
  • Could you tell me what is the right way to call it on command line? @khmarbaise – Mateus99 Nov 20 '19 at 01:40
  • @khmarbaise Sir, I have updated the answer, actually the current version is `1.4.10` – PythonLearner Nov 20 '19 at 13:04