简体   繁体   English

使用pitest时过滤ant中的类

[英]Filter classes in ant when using pitest

Let us consider this basic ant+pitest example: https://github.com/hcoles/pitest-ant-example 让我们考虑一下这个基本的ant + pitest示例: https : //github.com/hcoles/pitest-ant-example

The classpath to the test classes is defined as follow: 测试类的类路径定义如下:

<!-- 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>

Now, lets say I want to change it in order to filter out some classes. 现在,假设我要更改它以过滤掉某些类。 For example I want to include only the test classes whose name starts with "Partially": 例如,我只想包含名称以“ 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>

Unfortunately this solution gives me the following error: 不幸的是,此解决方案给了我以下错误:

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

The file /root/pitest-ant-example/build/test-classes/com/example/PartiallyTestedTest$1.class does actually exist. 文件/root/pitest-ant-example/build/test-classes/com/example/PartiallyTestedTest$1.class实际上存在。

What am I doing wrong ? 我究竟做错了什么 ? How can I filter the test classes I want to use ? 如何过滤要使用的测试类?

When you change from the simple 'pathelement' to the more complex 'fileset', the you change also the time when the classpath is evaluatet. 当您从简单的“路径元素”更改为更复杂的“文件集”时,您还更改了评估类路径的时间。

The simple 'pathelement' just tells ant to include a directory, but did not look into that directory when the path is defined. 简单的“ pathelement”仅告诉ant包含一个目录,但是在定义路径时没有查看该目录。

The more complex fileset is evaluated in that moment when the path is first used. 在第一次使用路径的那一刻,将评估更复杂的文件集。 In that moment the inner class (that one that contains a $) does not exists. 在那一刻,内部类(包含$的内部类)不存在。 So the class is missing at runtime. 因此,该类在运行时丢失。

You have to use a trick so that the path is evaluated at the right time, after the inner class has been generated. 您必须使用技巧,以便在生成内部类之后的正确时间评估路径。

You do not need to remove things from the classpath to select tests to run or classes to mutate. 您无需从类路径中删除内容即可选择要运行的测试或要进行突变的类。 Pitest provides its own filters. Pitest提供了自己的过滤器。

In recent versions these are 在最新版本中,这些是

  • targetClasses targetClasses
  • targetTests targetTests
  • excludedClasses excludeClasss
  • excludedTests 排除测试

Each accepts a list of globs. 每个接受一个glob列表。

Ant plugin usage is documented here http://pitest.org/quickstart/ant/ 此处记录了Ant插件的用法, 网址为http://pitest.org/quickstart/ant/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM