让我们考虑一下这个基本的蚂蚁+最可靠的例子: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>
现在,假设我想更改它以过滤掉一些类。例如,我想只包含名称以“Partially”开头的测试类:
<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
确实存在。
我究竟做错了什么 ?如何过滤我想要使用的测试类?
当您从简单的'pathelement'更改为更复杂的'fileset'时,您还会更改classpath的评估时间。
简单的'pathelement'只是告诉ant包含一个目录,但是在定义路径时没有查看该目录。
首次使用路径时,将评估更复杂的文件集。在那一刻,内部类(包含$的内部类)不存在。所以在运行时缺少类。
您必须使用技巧,以便在生成内部类之后在正确的时间评估路径。
您不需要从类路径中删除东西来选择要运行的测试或要变异的类。 Pitest提供自己的过滤器。
在最近的版本中这些是
每个都接受一个globs列表。
这里记录了ant插件的使用情况http://pitest.org/quickstart/ant/