让我们考虑一下这个基本的ant + pitest例子:https://github.com/hcoles/pitest-ant-example
测试类的类路径定义如下:
<!-- classpath for compiling and testing the code. Note it does not include pitest and it's dependencies -->
<path id="test.path">
<pathelement location="${classOutputDir}/classes" />
<pathelement location="${classOutputDir}/test-classes" />
<pathelement location="lib/junit-4.9.jar" />
</path>
现在,假设我想更改它以过滤掉一些类。 例如,我想只包括名称以&#34; Partially&#34;:
开头的测试类<path id="test.path">
<pathelement location="${classOutputDir}/classes" />
<fileset dir="${classOutputDir}/test-classes">
<include name="**/Partially*.class" />
<exclude name="**/ExcludedTest*.class" />
</fileset>
<pathelement location="lib/junit-4.9.jar" />
</path>
不幸的是,这个解决方案给了我以下错误:
pit:
[pitest] Exception in thread "main" org.pitest.util.PitError: error in opening zip file (/root/pitest-ant-example/build/test-classes/com/example/PartiallyTestedTest$1.class)
[pitest]
[pitest] Please copy and paste the information and the complete stacktrace below when reporting an issue
[pitest] VM : Java HotSpot(TM) 64-Bit Server VM
[pitest] Vendor : Oracle Corporation
[pitest] Version : 25.161-b12
[pitest] Uptime : 354
[pitest] Input ->
[pitest] BootClassPathSupported : true
[pitest]
[pitest] at org.pitest.util.Unchecked.translateCheckedException(Unchecked.java:25)
[pitest] at org.pitest.classpath.ArchiveClassPathRoot.getRoot(ArchiveClassPathRoot.java:120)
[pitest] at org.pitest.classpath.ArchiveClassPathRoot.getData(ArchiveClassPathRoot.java:46)
[pitest] at org.pitest.classpath.CompoundClassPathRoot.getData(CompoundClassPathRoot.java:27)
[pitest] at org.pitest.classpath.ClassPath.getClassData(ClassPath.java:97)
[pitest] at org.pitest.classpath.ClassPathByteArraySource.getBytes(ClassPathByteArraySource.java:41)
[pitest] at org.pitest.classinfo.Repository.querySource(Repository.java:82)
[pitest] at org.pitest.classinfo.Repository.nameToClassInfo(Repository.java:68)
[pitest] at org.pitest.classinfo.Repository.fetchClass(Repository.java:60)
[pitest] at org.pitest.mutationtest.config.ConfigurationFactory.createConfiguration(ConfigurationFactory.java:52)
[pitest] at org.pitest.mutationtest.config.LegacyTestFrameworkPlugin.createTestFrameworkConfiguration(LegacyTestFrameworkPlugin.java:38)
[pitest] at org.pitest.mutationtest.config.SettingsFactory.getTestFrameworkPlugin(SettingsFactory.java:133)
[pitest] at org.pitest.mutationtest.config.SettingsFactory.createCoverageOptions(SettingsFactory.java:142)
[pitest] at org.pitest.mutationtest.tooling.EntryPoint.execute(EntryPoint.java:80)
[pitest] at org.pitest.mutationtest.tooling.EntryPoint.execute(EntryPoint.java:45)
[pitest] at org.pitest.mutationtest.commandline.MutationCoverageReport.runReport(MutationCoverageReport.java:87)
[pitest] at org.pitest.mutationtest.commandline.MutationCoverageReport.main(MutationCoverageReport.java:45)
[pitest] Caused by: java.util.zip.ZipException: error in opening zip file
[pitest] at java.util.zip.ZipFile.open(Native Method)
[pitest] at java.util.zip.ZipFile.<init>(ZipFile.java:225)
[pitest] at java.util.zip.ZipFile.<init>(ZipFile.java:155)
[pitest] at java.util.zip.ZipFile.<init>(ZipFile.java:169)
[pitest] at org.pitest.classpath.ArchiveClassPathRoot.getRoot(ArchiveClassPathRoot.java:118)
[pitest] ... 15 more
BUILD FAILED
/root/pitest-ant-example/build.xml:109: /root/pitest-ant-example/build.xml:109: Java returned: 1
Total time: 2 seconds
文件/root/pitest-ant-example/build/test-classes/com/example/PartiallyTestedTest$1.class
确实存在。
我做错了什么?如何过滤我想要使用的测试类?
答案 0 :(得分:0)
当您从简单的'pathelement'更改为更复杂的'fileset'时,您也会更改classpath的评估时间。
简单的'pathelement'只是告诉ant包含一个目录,但是在定义路径时没有查看该目录。
首次使用路径时,将评估更复杂的文件集。在那一刻,内部类(包含$的内部类)不存在。所以在运行时缺少类。
你必须使用一个技巧,以便在生成内部类之后在正确的时间评估路径。
答案 1 :(得分:0)
您无需从类路径中删除内容以选择要运行的测试或要变异的类。 Pitest提供自己的过滤器。
在最近的版本中,这些是
每个人都接受一个globs列表。
此处记录了Ant插件的使用情况http://pitest.org/quickstart/ant/