2015-09-02 68 views
5

我想生成突變測試覆蓋。我正在PI測試 上進行POC,但它沒有考慮我的測試課並且失敗。我在pom.xml中配置了PTTest插件。我檢查了目標類的包名和目標測試類的包名在pom.xml文件中是否正確。PTTest失敗並且未生成突變覆蓋

我得到下面的錯誤 -

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來模擬對象。

回答

6

您的過濾器顯示不正確。 Pitest期望與每個班級的完全限定名稱相匹配的小球。

而不是

com.mutation.dx.pitestdemo

嘗試

com.mutation.dx.pitestdemo.*

* wilcard應該再在包匹配的所有類。

自1.2.0 targetClassestargetTests通常不需要在從maven運行時指定 - pitest現在將掃描項目並自動確定項目中定義了哪些包。

+0

謝謝亨利。你的解決方案解決了我的問題 –