我想生成突变测试覆盖率.我在PI Test上做POC,但它没有参加我的测试课程而且失败了.我在pom.xml中配置了PTTest插件.我在pom.xml文件中检查了目标类包名称和目标测试类包名称是否正确.
我收到以下错误 -
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)
Run Code Online (Sandbox Code Playgroud)
这是我的pom.xml文件 -
<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>
Run Code Online (Sandbox Code Playgroud)
下面是我想要产生变异的课程
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;
}
}
Run Code Online (Sandbox Code Playgroud)
以下是我的考试 -
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);
}
}
Run Code Online (Sandbox Code Playgroud)
我正在使用mockito来模拟对象.
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.