2017-02-15 63 views
2

到目前为止,我根据包名或类名排除某些类。有什么办法可以排除下面给出的Enums吗?从代码覆盖范围中排除枚举类?

package com.*; 

public enum Quality { 
    high,normal,low; 
} 

覆盖范围我使用maven-surefire插件与JUnit和JMockit。而我的报道的设置是这样

<build> 
<plugins> 
.... 
<plugin> 
    <groupId>org.apache.maven.plugins</groupId> 
    <artifactId>maven-surefire-plugin</artifactId> 
    <version>2.18.1</version> 
    <dependencies> 
     <dependency> 
      <groupId>org.apache.maven.surefire</groupId> 
      <artifactId>surefire-junit4</artifactId> 
      <version>2.18.1</version> 
     </dependency> 
    </dependencies> 
    <configuration> 
     <systemPropertyVariables> 
      <coverage-excludes>com.test.*,*IT.java</coverage-excludes> 
     </systemPropertyVariables> 
    </configuration> 
</plugin> 
.... 
</build> 
<dependencies> 
    .... 
     <dependency> 
      <groupId>org.jmockit</groupId> 
      <artifactId>jmockit</artifactId> 
      <version>1.17</version> 
     </dependency> 
     <dependency> 
      <groupId>org.jmockit</groupId> 
      <artifactId>jmockit-coverage</artifactId> 
      <version>1.17</version> 
     </dependency> 
     <dependency> 
      <groupId>junit</groupId> 
      <artifactId>junit</artifactId> 
      <version>4.11</version> 
     </dependency> 
    ....  
    </dependencies> 
+0

为什么要排除枚举?当然,如果你的一些生产代码使用这些枚举,它们将被覆盖,否则它会提示你没有使用某个值。 – GauravJ

回答

1

排除属性接受一个正则表达式。您可以按照您的应用程序代码约定使得所有枚举有他们的名字,如QualityEnum.java一个共同的模式,那么你可以申请一个正则表达式过滤排除

<exclude>%regex[*Enum.java], com.test.*</exclude> 

确保其他非枚举类避免这个约定。或者,在每个模块中都有一个专用子包用于枚举,并排除子包

+0

是的,我可以做到这一点。但是我想根据它的内容排除名称后缀。如果我想排除抽象类,引入另一个修复后模式,但是建议很好! – mavi

+1

我会认为这将涉及为surefire写一个新的排除过滤器实现,可以做InstanceOf操作@mavi –