2010-12-08 33 views

回答

16

当然,没问题:

<plugin> 
    <groupId>org.apache.maven.plugins</groupId> 
    <artifactId>maven-surefire-plugin</artifactId> 
    <version>2.6</version> 
    <configuration> 
     <excludes> 
     <!-- classes that include the name Dao --> 
     <exclude>**/*Dao*.java</exclude> 
     <!-- classes in a package whose last segment is named dao --> 
     <exclude>**/dao/*.java</exclude> 
     </excludes> 
    </configuration> 
</plugin> 

参考:

(该不包括不能被经由命令行配置,所以如果你想 有条件地打开此行为,您将不得不定义一个配置文件并在命令行上激活该配置文件)

+2

6年后,surefire.excludes仍然不起作用的命令行。 – 2017-02-02 01:16:54

37

让我扩展Sean的答案。这就是你在pom.xml设置:

<properties> 
    <exclude.tests>nothing-to-exclude</exclude.tests> 
</properties> 
<profiles> 
    <profile> 
    <id>fast</id> 
    <properties> 
     <exclude.tests>**/*Dao*.java</exclude.tests> 
    </properties> 
    </profile> 
</profiles> 
<plugin> 
    <groupId>org.apache.maven.plugins</groupId> 
    <artifactId>maven-surefire-plugin</artifactId> 
    <configuration> 
    <excludes> 
    <exclude>${exclude.tests}</exclude> 
    </excludes> 
    </configuration> 
</plugin> 

然后在CI开始他们是这样的:

mvn -Pfast test 

就是这样。

1

可以使用命令行排除测试;使用!来排除。

注意:我不确定但可能需要2.19.1或更高版本的surefire才能正常工作。

例子:

此将不运行TestHCatLoaderEncryption

mvn install '-Dtest=!TestHCatLoaderEncryption' 

排除包:

mvn install '-Dtest=!org.apache.hadoop.**' 

可以与正滤波器以及被组合;以下将运行0测试:

mvn install '-Dtest=Test*CatLoaderEncryption,!TestHCatLoaderEncryption' 
相关问题