PTTest 失败且未生成突变覆盖率
Posted
技术标签:
【中文标题】PTTest 失败且未生成突变覆盖率【英文标题】:PTTest is failing and not generating mutation coverage 【发布时间】:2015-11-27 12:42:36 【问题描述】:我想生成突变测试覆盖率。我在 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)
这是我的 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>
下面是我想要生成突变的班级
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;
下面是我的测试类-
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);
我正在使用 mockito 来模拟对象。
【问题讨论】:
【参考方案1】:您的过滤器看起来不正确。 Pitest 期望与每个类的完全限定名称匹配的 glob。
而不是
com.mutation.dx.pitestdemo
试试
com.mutation.dx.pitestdemo.*
*
通配符应该匹配包中的所有类。
从 1.2.0 开始,从 maven 运行时通常不需要指定 targetClasses
和 targetTests
- Pitest 现在将扫描项目并自动确定项目中定义了哪些包。
【讨论】:
以上是关于PTTest 失败且未生成突变覆盖率的主要内容,如果未能解决你的问题,请参考以下文章