I want to generate mutation test coverage. I am doing POC on PI Test but it is not taking my test classes and failing. I have configured PTTest plugin in pom.xml. I checked the target class package name and target test class package name are correct in pom.xml file.
I am getting below error -
10:50:29 AM PIT >> INFO : Mutating from D:\IR\workspace\cleanup_trunk\reporterDx-service\target\classes
10:50:29 AM PIT >> INFO : Verbose logging is disabled. If you encounter an problem please enable it before reporting an issue.
10:50:30 AM PIT >> INFO : Sending 0 test classes to slave
10:50:30 AM PIT >> INFO : Sent tests to slave
10:50:30 AM PIT >> INFO : Calculated coverage in 0 seconds.
10:50:30 AM PIT >> INFO : Created 0 mutation test units
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 4.575s
[INFO] Finished at: Wed Sep 02 10:50:30 IST 2015
[INFO] Final Memory: 13M/244M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.pitest:pitest-maven:1.1.4:mutationCoverage (default-cli) on project reporterDx-service: Execution default-cli of goal org.pitest:p
itest-maven:1.1.4:mutationCoverage failed: No mutations found. This probably means there is an issue with either the supplied classpath or filters.
[ERROR] See http://pitest.org for more details.
[ERROR] -> [Help 1]
org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal org.pitest:pitest-maven:1.1.4:mutationCoverage (default-cli) on project reporterDx-ser
vice: Execution default-cli of goal org.pitest:pitest-maven:1.1.4:mutationCoverage failed: No mutations found. This probably means there is an issue with either the
supplied classpath or filters.
See http://pitest.org for more details.
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:225)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:153)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:145)
at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:84)
at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:59)
at org.apache.maven.lifecycle.internal.LifecycleStarter.singleThreadedBuild(LifecycleStarter.java:183)
at org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:161)
at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:320)
at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:156)
at org.apache.maven.cli.MavenCli.execute(MavenCli.java:537)
at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:196)
at org.apache.maven.cli.MavenCli.main(MavenCli.java:141)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:290)
at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:230)
at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:409)
at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:352)
Caused by: org.apache.maven.plugin.PluginExecutionException: Execution default-cli of goal org.pitest:pitest-maven:1.1.4:mutationCoverage failed: No mutations found.
This probably means there is an issue with either the supplied classpath or filters.
See http://pitest.org for more details.
at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:110)
This is my pom.xml file -
<plugin>
<groupId>org.pitest</groupId>
<artifactId>pitest-maven</artifactId>
<version>1.1.4</version>
<configuration>
<targetClasses>
<param>com.mutation.dx.pitestdemo</param>
</targetClasses>
<targetTests>
<param>com.mutation.dx.pitestdemo</param>
</targetTests>
</configuration>
</plugin>
below is my class on which I want to generate mutation
package com.mutation.dx.pitestdemo;
import org.springframework.beans.factory.annotation.Autowired;
public class PIDemoImpl implements PIDemo {
@Autowired
private PIDemoDao piDemoDao;
@Override
public PIDto getPIDetails(String name, int firstNumber,int secondNumber) {
int thirdNumber = firstNumber * secondNumber;
PIDomain piDomain = piDemoDao.getPIDomain(name, thirdNumber);
if(piDomain != null) {
PIDto piDto = new PIDto();
piDto.setName(piDomain.getName());
int result = piDomain.getX() + piDomain.getY();
if(result >= 0 ) {
piDto.setResult(result);
}
return piDto;
}
return null;
}
}
below is my test class-
package com.mutation.dx.pitestdemo;
import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import static org.mockito.Mockito.when;
import static org.mockito.Mockito.verify;
import org.mockito.runners.MockitoJUnitRunner;
import com.mutation.dx.pitestdemo.PIDemoImpl;
@RunWith(MockitoJUnitRunner.class)
public class PIDemoImplTest {
@Mock
private PIDemoDao piDemoDao;
@InjectMocks
PIDemoImpl piDemoImpl;
@Test
public void getPIDetailsTest(){
String name = "Persistent";
int firstNumber = 0;
int secondNumber = 10;
int thirdNumber = 0;
PIDomain piDomain = new PIDomain();
piDomain.setName(name);
piDomain.setX(2);
piDomain.setY(2);
when(piDemoDao.getPIDomain(name, thirdNumber)).thenReturn(piDomain);
PIDto piDto = piDemoImpl.getPIDetails(name , firstNumber, secondNumber);
Assert.assertNotNull(piDto);
Assert.assertEquals(piDto.getName(),name);
verify(piDemoDao).getPIDomain(name, thirdNumber);
}
}
I am using mockito to mock the objects.
Your filters do not look correct. Pitest expects globs that are matched against the fully qualified name of each class.
Instead of
com.mutation.dx.pitestdemo
Try
com.mutation.dx.pitestdemo.*
The *
wilcard should then match all classes in the package.
As of 1.2.0 targetClasses
and targetTests
do not usually need to be specified when running from maven - pitest will now scan the project and automatically determine which packages are defined in the project.