我有一个问题,就是PITest跳过了我的一些测试。它没有报告被测试的类的行覆盖和所有的突变保持活着:
用Collections.emptyList代替了.→NO_COVERAGE的返回值
下面的列表是空的:
试验检查
我确实检查了以下几点:
类和测试的类文件被支持在类路径verbose=true
H 113控制台上没有出现错误,即使在用
H 216F 217>时<pitest
pitClasspath="pit.path"
classPath="mutation.path"
targetClasses="my.package1.*,my.package2.*,my.package3.*"
targetTests="my.package1.Class1Test,my.package2.sub.Class2Test,my.package3.sub.Class3Test"
reportDir="pitest"
sourceDir="src,testsrc"
timestampedReports="false"
outputFormats="HTML,XML"
excludedClasses="my.package1.*Test,my.package2.*Test,my.package3.*Test"
verbose="true"
/>我使用的是PITest版本1.4.11,但我也用1.6.2和1.4.3进行了测试。另外,我还使用了Java 1.8.0_211和ant1.9.13。
我在:https://github.com/johannesn/pittestskippingtests建立了一个测试项目
这是此示例项目的日志输出:
Buildfile: .../pitestskipingtests/build.xml
mutationCoverage:
[delete] Deleting directory .../pitestskipingtests/classes
[delete] Deleting directory .../pitestskipingtests/testclasses
[mkdir] Created dir: .../pitestskipingtests/classes
[mkdir] Created dir: .../pitestskipingtests/testclasses
[javac] .../pitestskipingtests/build.xml:30: warning: 'includeantruntime' was not set, defaulting to build.sysclasspath=last; set to false for repeatable builds
[javac] Compiling 3 source files to .../pitestskipingtests/classes
[javac] .../pitestskipingtests/build.xml:31: warning: 'includeantruntime' was not set, defaulting to build.sysclasspath=last; set to false for repeatable builds
[javac] Compiling 3 source files to .../pitestskipingtests/testclasses
[pitest] 19:24:08 PIT >> INFO : ---------------------------------------------------------------------------
[pitest] 19:24:08 PIT >> INFO : Enabled (+) and disabled (-) features.
[pitest] 19:24:08 PIT >> INFO : -----------------------------------------
[pitest] 19:24:08 PIT >> INFO : +FFBLOCK Filters mutations in code duplicated by finally block inlining
[pitest] 19:24:08 PIT >> INFO : +FSTATI Filters mutations in static initializers and code called only from them
[pitest] 19:24:08 PIT >> INFO : +FSEQUIVEQUALS Filters equivalent mutations that affect only performance in short cutting equals methods
[pitest] 19:24:08 PIT >> INFO : +FFEACH Filters mutations in compiler generated code that implements for each loops
[pitest] 19:24:08 PIT >> INFO : +FINFINC Filters mutations to increments that may cause infinite loops
[pitest] 19:24:08 PIT >> INFO : +FFLOOP Filters any mutations to increments in for loops as they may cause timeouts
[pitest] 19:24:08 PIT >> INFO : +FRETEQUIV Filters return vals mutants with bytecode equivalent to the unmutated class
[pitest] 19:24:08 PIT >> INFO : +FINULL Filters mutations in compiler generated code that checks for null by calling getClass
[pitest] 19:24:08 PIT >> INFO : +FTRYWR Filters mutations in code generated for try with resources statements
[pitest] 19:24:08 PIT >> INFO : +FKOTLIN Filters out junk mutations in bytecode created by compiler for kotlin language features
[pitest] 19:24:08 PIT >> INFO : +FSTATINIT Filters mutations in static initializers and code called only from them
[pitest] 19:24:08 PIT >> INFO : +FLOGCALL Filters mutations in code that makes calls to logging frameworks
[pitest] 19:24:08 PIT >> INFO : +FINFIT Filters mutations that may cause infinite loops by removing calls to iterator.next
[pitest] 19:24:08 PIT >> INFO : +FANN Filters mutations in classes and methods with matching annotations of class or runtime retention
[pitest] 19:24:08 PIT >> INFO : [annotation] Annotation to avoid (full package name not required)
[pitest] 19:24:08 PIT >> INFO : -CLASSLIMIT Limits the maximum number of mutations per class
[pitest] 19:24:08 PIT >> INFO : [limit] Integer value for maximum mutations to create per class
[pitest] 19:24:08 PIT >> INFO : -EXPORT Exports mutants bytecode and other details to disk
[pitest] 19:24:08 PIT >> INFO : ---------------------------------------------------------------------------
[pitest] 19:24:08 PIT >> FINE : Running report with ReportOptions [targetClasses=[my.package1.*, my.package2.*, my.package3.*], excludedMethods=[], excludedClasses=[my.package1.*Test, my.package2.*Test, my.package3.*Test], excludedTestClasses=[], codePaths=[], reportDir=pitest, historyInputLocation=null, historyOutputLocation=null, sourceDirs=[src, testsrc], classPathElements=[.../pitestskipingtests/resources/pitest/pitest-1.4.3.jar, .../pitestskipingtests/testclasses, .../pitestskipingtests/classes, .../pitestskipingtests/lib/junit-4.12.jar], mutators=[], features=[], dependencyAnalysisMaxDistance=-1, jvmArgs=[], numberOfThreads=1, timeoutFactor=1.25, timeoutConstant=4000, targetTests=[^my\.package1\.Class1Test$, ^my\.package2\.sub\.Class2Test$, ^my\.package3\.sub\.Class3Test$], loggingClasses=[], maxMutationsPerClass=0, verbose=true, failWhenNoMutations=true, outputs=[HTML, XML], groupConfig=TestGroupConfig [excludedGroups=[], includedGroups=[]], fullMutationMatrix=false, mutationUnitSize=0, shouldCreateTimestampedReports=false, detectInlinedCode=false, exportLineCoverage=false, mutationThreshold=0, coverageThreshold=0, mutationEngine=gregor, javaExecutable=null, includeLaunchClasspath=false, properties={}, maxSurvivors=-1, excludedRunners=[], includedTestMethods=[], testPlugin=junit, useClasspathJar=false]
[pitest] 19:24:08 PIT >> FINE : System class path is .../pitestskipingtests/resources/pitest/pitest-1.4.3.jar:.../pitestskipingtests/resources/pitest/pitest-ant-1.4.3.jar:.../pitestskipingtests/resources/pitest/pitest-entry-1.4.3.jar:.../pitestskipingtests/resources/pitest/xmlpull-1.1.3.1.jar:.../pitestskipingtests/resources/pitest/xstream-1.4.11.1.jar:.../pitestskipingtests/lib/junit-4.12.jar
[pitest] 19:24:08 PIT >> FINE : Maximum available memory is 3641 mb
[pitest] 19:24:08 PIT >> FINE : MINION : Installing PIT agent
[pitest]
[pitest] 19:24:09 PIT >> INFO : Sending 3 test classes to minion
[pitest] 19:24:09 PIT >> INFO : Sent tests to minion
[pitest] 19:24:09 PIT >> FINE : Coverage generator Minion exited ok
[pitest] 19:24:09 PIT >> INFO : Calculated coverage in 0 seconds.
[pitest] 19:24:09 PIT >> FINE : Used memory after coverage calculation 14 mb
[pitest] 19:24:09 PIT >> FINE : Free Memory after coverage calculation 231 mb
[pitest] 19:24:09 PIT >> FINE : According to coverage no tests hit the mutation MutationDetails [id=MutationIdentifier [location=Location [clazz=my.package1.Class1, method=method1, methodDesc=()Ljava/lang/String;], indexes=[4], mutator=org.pitest.mutationtest.engine.gregor.mutators.ReturnValsMutator], filename=Class1.java, block=1, lineNumber=5, description=mutated return of Object value for my/package1/Class1::method1 to ( if (x != null) null else throw new RuntimeException ), testsInOrder=[], isInFinallyBlock=false, poison=NORMAL]
[pitest] 19:24:09 PIT >> FINE : According to coverage no tests hit the mutation MutationDetails [id=MutationIdentifier [location=Location [clazz=my.package2.sub.Class2, method=method1, methodDesc=()Ljava/lang/String;], indexes=[4], mutator=org.pitest.mutationtest.engine.gregor.mutators.ReturnValsMutator], filename=Class2.java, block=1, lineNumber=5, description=mutated return of Object value for my/package2/sub/Class2::method1 to ( if (x != null) null else throw new RuntimeException ), testsInOrder=[], isInFinallyBlock=false, poison=NORMAL]
[pitest] 19:24:09 PIT >> FINE : According to coverage no tests hit the mutation MutationDetails [id=MutationIdentifier [location=Location [clazz=my.package3.sub.Class3, method=method1, methodDesc=()Ljava/lang/String;], indexes=[4], mutator=org.pitest.mutationtest.engine.gregor.mutators.ReturnValsMutator], filename=Class3.java, block=1, lineNumber=6, description=mutated return of Object value for my/package3/sub/Class3::method1 to ( if (x != null) null else throw new RuntimeException ), testsInOrder=[], isInFinallyBlock=false, poison=NORMAL]
[pitest] 19:24:09 PIT >> INFO : Created 3 mutation test units
[pitest] 19:24:09 PIT >> FINE : Used memory before analysis start 23 mb
[pitest] 19:24:09 PIT >> FINE : Free Memory before analysis start 222 mb
[pitest] 19:24:09 PIT >> FINE : Running 3 units
[pitest] ================================================================================
[pitest] - Mutators
[pitest] ================================================================================
[pitest] > org.pitest.mutationtest.engine.gregor.mutators.ReturnValsMutator
[pitest] >> Generated 3 Killed 0 (0%)
[pitest] > KILLED 0 SURVIVED 0 TIMED_OUT 0 NON_VIABLE 0
[pitest] > MEMORY_ERROR 0 NOT_STARTED 0 STARTED 0 RUN_ERROR 0
[pitest] > NO_COVERAGE 3
[pitest] --------------------------------------------------------------------------------
[pitest] ================================================================================
[pitest] - Timings
[pitest] ================================================================================
[pitest] > scan classpath : < 1 second
[pitest] > coverage and dependency analysis : < 1 second
[pitest] > build mutation tests : < 1 second
[pitest] > run mutation analysis : < 1 second
[pitest] --------------------------------------------------------------------------------
[pitest] > Total : < 1 second
[pitest] --------------------------------------------------------------------------------
[pitest] ================================================================================
[pitest] - Statistics
[pitest] ================================================================================
[pitest] >> Generated 3 mutations Killed 0 (0%)
[pitest] >> Ran 0 tests (0 tests per mutation)
[pitest] 19:24:09 PIT >> INFO : Completed in 0 seconds
BUILD SUCCESSFUL
Total time: 1 second发布于 2021-02-22 13:54:24
经过大量的调试和尝试之后,我发现没有找到测试方法,因为缺少junit依赖的hamcrest。
对于遇到类似问题的其他人,请尝试调试以下方法:
org.pitest.junit.RunnerSuiteFinder#apply取决于您的测试设置(例如,如果您使用junit )可能是一个不同的子类
org.pitest.testapi.TestSuiteFinder我经历了以下例外:
java.lang.NoClassDefFoundError: org/hamcrest/SelfDescribing
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:763)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:468)
at java.net.URLClassLoader.access$100(URLClassLoader.java:74)
at java.net.URLClassLoader$1.run(URLClassLoader.java:369)
at java.net.URLClassLoader$1.run(URLClassLoader.java:363)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:362)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:349)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
at org.junit.internal.builders.JUnit4Builder.runnerForClass(JUnit4Builder.java:10)
at org.junit.runners.model.RunnerBuilder.safeRunnerForClass(RunnerBuilder.java:70)
at org.junit.internal.builders.AllDefaultPossibilitiesBuilder.runnerForClass(AllDefaultPossibilitiesBuilder.java:37)
at org.pitest.junit.adapter.AdaptedJUnitTestUnit.createRunner(AdaptedJUnitTestUnit.java:107)
at org.pitest.junit.RunnerSuiteFinder.apply(RunnerSuiteFinder.java:40)
at org.pitest.junit.RunnerSuiteFinder.apply(RunnerSuiteFinder.java:35)
at org.pitest.extension.common.CompoundTestSuiteFinder.apply(CompoundTestSuiteFinder.java:20)
at org.pitest.extension.common.CompoundTestSuiteFinder.apply(CompoundTestSuiteFinder.java:9)
at org.pitest.testapi.execute.FindTestUnits.findTestUnits(FindTestUnits.java:47)
at org.pitest.testapi.execute.FindTestUnits.getTestUnits(FindTestUnits.java:40)
at org.pitest.testapi.execute.FindTestUnits.findTestUnitsForAllSuppliedClasses(FindTestUnits.java:29)
at org.pitest.coverage.execute.CoverageMinion.discoverTests(CoverageMinion.java:156)
at org.pitest.coverage.execute.CoverageMinion.getTestsFromParent(CoverageMinion.java:137)
at org.pitest.coverage.execute.CoverageMinion.main(CoverageMinion.java:83)
Caused by: java.lang.ClassNotFoundException: org.hamcrest.SelfDescribing
at java.net.URLClassLoader.findClass(URLClassLoader.java:382)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:349)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
... 26 more异常是runner变量的一部分。使用以下方法打印:
((ErrorReportingRunner) runner).causes.get(0).printStackTrace()https://stackoverflow.com/questions/66154859
复制相似问题