2016-01-22 117 views
3

我的gradle pitest無法給我正確的結果。看起來它無法找到我的測試文件。pitest找不到junit測試

我有以下的build.gradle文件:

apply plugin: "java" apply plugin: "maven" apply plugin: "info.solidsoft.pitest" 

group = "myorg" version = 1.0 

repositories { 
    mavenCentral() } 

sourceSets.all { set -> 
    def jarTask = task("${set.name}Jar", type: Jar) { 
     baseName = baseName + "-$set.name" 
     from set.output 
    } 

    artifacts { 
     archives jarTask 
    } } 

sourceSets { 
    api 
    impl main{  java {   srcDir 'src/api/java'   srcDir 'src/impl/java'  } } test {  java {   srcDir 'src/test/java'  } } } 

buildscript { 
    repositories { 
     mavenCentral() 
     //Needed only for SNAPSHOT versions 
     //maven { url "http://oss.sonatype.org/content/repositories/snapshots/" } 
    } 
    dependencies { 
     classpath 'info.solidsoft.gradle.pitest:gradle-pitest-plugin:1.1.6' 
    } } 

dependencies { 
    apiCompile 'commons-codec:commons-codec:1.5' 

    implCompile sourceSets.api.output 
    implCompile 'commons-lang:commons-lang:2.6' 

    testCompile 'junit:junit:4.9' 
    testCompile sourceSets.api.output 
    testCompile sourceSets.impl.output 
    runtime configurations.apiRuntime 
    runtime configurations.implRuntime } 

jar { 
    from sourceSets.api.output 
    from sourceSets.impl.output } 

pitest { println sourceSets.main 

    targetClasses = ['doubler.*']  targetTests = ['doubler.*'] verbose="on" } 

當我運行它,我得到以下的輸出:

C:\Users\lukkezenm\workspace\pittest\pittest>gradlew pitest 
source set 'main' 
:compileApiJava 
:processApiResources UP-TO-DATE 
:apiClasses 
:compileImplJava 
:processImplResources UP-TO-DATE 
:implClasses 
:compileJava 
:processResources UP-TO-DATE 
:classes 
:compileTestJava 
:processTestResources UP-TO-DATE 
:testClasses 
:pitest 
2:57:49 PM PIT >> FINE : Running report with ReportOptions [targetClasses=[^doubler\..*$], ex 
cludedMethods=[], excludedClasses=[], codePaths=[C:\Users\lukkezenm\workspace\pittest\pittest 
\build\classes\main], reportDir=C:\Users\lukkezenm\workspace\pittest\pittest\build\reports\pi 
test, historyInputLocation=null, historyOutputLocation=null, sourceDirs=[C:\Users\lukkezenm\w 
orkspace\pittest\pittest\src\main\resources, C:\Users\lukkezenm\workspace\pittest\pittest\src 
\main\java, C:\Users\lukkezenm\workspace\pittest\pittest\src\api\java, C:\Users\lukkezenm\wor 
kspace\pittest\pittest\src\impl\java], classPathElements=[C:\Users\lukkezenm\.gradle\caches\m 
odules-2\files-2.1\org.pitest\pitest\1.1.6\3f0653443fe5ec2546c91140d3dcf007cd772dad\pitest-1. 
1.6.jar, C:\Users\lukkezenm\workspace\pittest\pittest\build\classes\test, C:\Users\lukkezenm\ 
workspace\pittest\pittest\build\resources\test, C:\Users\lukkezenm\workspace\pittest\pittest\ 
build\classes\main, C:\Users\lukkezenm\workspace\pittest\pittest\build\resources\main, C:\Use 
rs\lukkezenm\workspace\pittest\pittest\build\classes\api, C:\Users\lukkezenm\workspace\pittes 
t\pittest\build\resources\api, C:\Users\lukkezenm\workspace\pittest\pittest\build\classes\imp 
l, C:\Users\lukkezenm\workspace\pittest\pittest\build\resources\impl, C:\Users\lukkezenm\.gra 
dle\caches\modules-2\files-2.1\commons-codec\commons-codec\1.5\cf993e250ff71804754ec2734a16f2 
3c0be99f70\commons-codec-1.5.jar, C:\Users\lukkezenm\.gradle\caches\modules-2\files-2.1\commo 
ns-lang\commons-lang\2.6\ce1edb914c94ebc388f086c6827e8bdeec71ac2\commons-lang-2.6.jar, C:\Use 
rs\lukkezenm\.gradle\caches\modules-2\files-2.1\junit\junit\4.9\1013627e3993319870863a0200340 
04717505815\junit-4.9.jar, C:\Users\lukkezenm\.gradle\caches\modules-2\files-2.1\org.hamcrest 
\hamcrest-core\1.1\860340562250678d1a344907ac75754e259cdb14\hamcrest-core-1.1.jar], mutators= 
[], dependencyAnalysisMaxDistance=-1, mutateStaticInitializers=false, jvmArgs=[], numberOfThr 
eads=1, timeoutFactor=1.25, timeoutConstant=4000, targetTests=[^doubler\..*$], loggingClasses 
=[                       ] 
, maxMutationsPerClass=0, verbose=true, failWhenNoMutations=true, outputs=[HTML], groupConfig 
=TestGroupConfig [excludedGroups=[], includedGroups=[]], mutationUnitSize=0, shouldCreateTime 
stampedReports=true, detectInlinedCode=false, exportLineCoverage=false, mutationThreshold=0, 
coverageThreshold=0, mutationEngine=gregor, javaExecutable=null, includeLaunchClasspath=false 
] 
2:57:49 PM PIT >> FINE : System class path is C:\Users\lukkezenm\.gradle\caches\modules-2\fil 
es-2.1\org.pitest\pitest-command-line\1.1.6\4abe3b86a567be1be40f1582b6a56fdc333a574a\pitest-c 
ommand-line-1.1.6.jar;C:\Users\lukkezenm\.gradle\caches\modules-2\files-2.1\org.pitest\pitest 
\1.1.6\3f0653443fe5ec2546c91140d3dcf007cd772dad\pitest-1.1.6.jar;C:\Users\lukkezenm\.gradle\c 
aches\modules-2\files-2.1\junit\junit\4.11\4e031bb61df09069aeb2bffb4019e7a5034a4ee0\junit-4.1 
1.jar;C:\Users\lukkezenm\.gradle\caches\modules-2\files-2.1\org.hamcrest\hamcrest-core\1.3\42 
a25dc3219429f0e5d060061f71acb49bf010a0\hamcrest-core-1.3.jar 
2:57:49 PM PIT >> FINE : Maximum available memory is 247 mb 
2:57:49 PM PIT >> FINE : using port 8092 
2:57:49 PM PIT >> INFO : Sending 1 test classes to slave 
2:57:49 PM PIT >> INFO : Sent tests to slave 
2:57:49 PM PIT >> FINE : Coverage generator Slave exited ok 
2:57:49 PM PIT >> INFO : Calculated coverage in 0 seconds. 
2:57:49 PM PIT >> FINE : Used memory after coverage calculation 4 mb 
2:57:49 PM PIT >> FINE : Free Memory after coverage calculation 10 mb 
2:57:49 PM PIT >> FINE : According to coverage no tests hit the mutation MutationDetails [id= 
MutationIdentifier [location=Location [clazz=doubler.impl.DoublerImpl, method=doubleIt, metho 
dDesc=(I)I], indexes=[5], mutator=org.pitest.mutationtest.engine.gregor.mutators.NegateCondit 
ionalsMutator], filename=DoublerImpl.java, block=1, lineNumber=7, description=negated conditi 
onal, testsInOrder=[]] 
2:57:49 PM PIT >> FINE : According to coverage no tests hit the mutation MutationDetails [id= 
MutationIdentifier [location=Location [clazz=doubler.impl.DoublerImpl, method=doubleIt, metho 
dDesc=(I)I], indexes=[5], mutator=org.pitest.mutationtest.engine.gregor.mutators.Conditionals 
BoundaryMutator], filename=DoublerImpl.java, block=1, lineNumber=7, description=changed condi 
tional boundary, testsInOrder=[]] 
2:57:49 PM PIT >> FINE : According to coverage no tests hit the mutation MutationDetails [id= 
MutationIdentifier [location=Location [clazz=doubler.impl.DoublerImpl, method=doubleIt, metho 
dDesc=(I)I], indexes=[9], mutator=org.pitest.mutationtest.engine.gregor.mutators.ReturnValsMu 
tator], filename=DoublerImpl.java, block=2, lineNumber=9, description=replaced return of inte 
ger sized value with (x == 0 ? 1 : 0), testsInOrder=[]] 
2:57:49 PM PIT >> FINE : According to coverage no tests hit the mutation MutationDetails [id= 
MutationIdentifier [location=Location [clazz=doubler.impl.DoublerImpl, method=doubleIt, metho 
dDesc=(I)I], indexes=[13], mutator=org.pitest.mutationtest.engine.gregor.mutators.IncrementsM 
utator], filename=DoublerImpl.java, block=3, lineNumber=11, description=Changed increment fro 
m 1 to -1, testsInOrder=[]] 
2:57:49 PM PIT >> FINE : According to coverage no tests hit the mutation MutationDetails [id= 
MutationIdentifier [location=Location [clazz=doubler.impl.DoublerImpl, method=doubleIt, metho 
dDesc=(I)I], indexes=[18], mutator=org.pitest.mutationtest.engine.gregor.mutators.MathMutator 
], filename=DoublerImpl.java, block=3, lineNumber=12, description=Replaced integer multiplica 
tion with division, testsInOrder=[]] 
2:57:49 PM PIT >> FINE : According to coverage no tests hit the mutation MutationDetails [id= 
MutationIdentifier [location=Location [clazz=doubler.impl.DoublerImpl, method=doubleIt, metho 
dDesc=(I)I], indexes=[19], mutator=org.pitest.mutationtest.engine.gregor.mutators.ReturnValsM 
utator], filename=DoublerImpl.java, block=3, lineNumber=12, description=replaced return of in 
teger sized value with (x ==                0 
? 1 : 0), testsInOrder=[]] 
2:57:49 PM PIT >> FINE : According to coverage no tests hit the mutation MutationDetails [id= 
MutationIdentifier [location=Location [clazz=doubler.impl.DoublerImpl, method=testIt, methodD 
esc=(I)I], indexes=[3], mutator=org.pitest.mutationtest.engine.gregor.mutators.IncrementsMuta 
tor], filename=DoublerImpl.java, block=4, lineNumber=16, description=Changed increment from 1 
to -1, testsInOrder=[]] 
2:57:49 PM PIT >> FINE : According to coverage no tests hit the mutation MutationDetails [id= 
MutationIdentifier [location=Location [clazz=doubler.impl.DoublerImpl, method=testIt, methodD 
esc=(I)I], indexes=[7], mutator=org.pitest.mutationtest.engine.gregor.mutators.ReturnValsMuta 
tor], filename=DoublerImpl.java, block=4, lineNumber=17, description=replaced return of integ 
er sized value with (x == 0 ? 1 : 0), testsInOrder=[]] 
2:57:49 PM PIT >> INFO : Created 1 mutation test units 
2:57:49 PM PIT >> FINE : Used memory before analysis start 5 mb 
2:57:49 PM PIT >> FINE : Free Memory before analysis start 10 mb 
2:57:49 PM PIT >> FINE : Running 1 units 
2:57:49 PM PIT >> INFO : Completed in 0 seconds 
================================================================================ 
- Timings 
================================================================================ 
> scan classpath : < 1 second 
> coverage and dependency analysis : < 1 second 
> build mutation tests : < 1 second 
> run mutation analysis : < 1 second 
-------------------------------------------------------------------------------- 
> Total : < 1 second 
-------------------------------------------------------------------------------- 
================================================================================ 
- Statistics 
================================================================================ 
>> Generated 8 mutations Killed 0 (0%) 
>> Ran 0 tests (0 tests per mutation) 
================================================================================ 
- Mutators 
================================================================================ 
> org.pitest.mutationtest.engine.gregor.mutators.MathMutator 
>> Generated 1 Killed 0 (0%) 
> KILLED 0 SURVIVED 0 TIMED_OUT 0 NON_VIABLE 0 
> MEMORY_ERROR 0 NOT_STARTED 0 STARTED 0 RUN_ERROR 0 
> NO_COVERAGE 1 
-------------------------------------------------------------------------------- 
> org.pitest.mutationtest.engine.gregor.mutators.ConditionalsBoundaryMutator 
>> Generated 1 Killed 0 (0%) 
> KILLED 0 SURVIVED 0 TIMED_OUT 0 NON_VIABLE 0 
> MEMORY_ERROR 0 NOT_STARTED 0 STARTED 0 RUN_ERROR 0 
> NO_COVERAGE 1 
-------------------------------------------------------------------------------- 
> org.pitest.mutationtest.engine.gregor.mutators.ReturnValsMutator 
>> Generated 3 Killed 0 (0%) 
> KILLED 0 SURVIVED 0 TIMED_OUT 0 NON_VIABLE 0 
> MEMORY_ERROR 0 NOT_STARTED 0 STARTED 0 RUN_ERROR 0 
> NO_COVERAGE 3 
-------------------------------------------------------------------------------- 
> org.pitest.mutationtest.engine.gregor.mutators.IncrementsMutator 
>> Generated 2 Killed 0 (0%) 
> KILLED 0 SURVIVED 0 TIMED_OUT 0 NON_VIABLE 0 
> MEMORY_ERROR 0 NOT_STARTED 0 STARTED 0 RUN_ERROR 0 
> NO_COVERAGE 2 
-------------------------------------------------------------------------------- 
> org.pitest.mutationtest.engine.gregor.mutators.NegateConditionalsMutator 
>> Generated 1 Killed 0 (0%) 
> KILLED 0 SURVIVED 0 TIMED_OUT 0 NON_VIABLE 0 
> MEMORY_ERROR 0 NOT_STARTED 0 STARTED 0 RUN_ERROR 0 
> NO_COVERAGE 1 
-------------------------------------------------------------------------------- 

BUILD SUCCESSFUL 

Total time: 4.114 secs 
C:\Users\lukkezenm\workspace\pittest\pittest> 

輸出存儲在正確的文件夾。當我運行gradle測試時,它也運行良好。

+0

您有多少個測試班?他們看起來怎麼樣。輸出結果表明pitest已經找到了一個測試類,但它沒有提供覆蓋。 – henry

回答

2

有關此問題的一些其他信息在pitest用戶組中提供。

https://groups.google.com/forum/#!topic/pitusers/8C7BHh-Vb6Y

測試中運行這個樣子的。

@Test 
public void testIt2() { 
    assert new DoublerImpl().testIt(1) == 2; 
} 

Pitest正確地報告說這些測試提供了0%的類覆蓋率。沒有覆蓋範圍,因爲已經使用assert關鍵字。

除非在運行測試斷言的JVM中設置了-ea標誌被禁用。如果由編譯器

@Test 
public void testIt2() { 
    if (assertionsEnabled) { 
     assert new DoublerImpl().testIt(1) == 2; 
    } 
} 

作爲斷言未啓用沒有代碼被執行生成解決此代碼塊有基本上是隱藏的。

要解決該問題,請改用內置的JUnit聲明。

http://junit.sourceforge.net/javadoc/org/junit/Assert.html