我的gradle pitest无法给我正确的结果。看起来它无法找到我的测试文件。
我有以下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 :(得分: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的JVM中设置-ea
标志,否则将禁用断言。基本上隐藏了if编译器生成的代码
@Test
public void testIt2() {
if (assertionsEnabled) {
assert new DoublerImpl().testIt(1) == 2;
}
}
由于未启用断言,因此不会执行任何代码。
要解决此问题,请使用内置的JUnit断言。