[英]maven-surefire-plugin include/exclude precedence
When using the maven-surefire-plugin and both includes and excludes, which order are they processed in? 当使用maven-surefire-plugin并且包含和排除时,它们处理的顺序是什么? Furthermore, if you have 3 sets of tests, the first being the base set, the second and third being special cases, can you use profiles to further include/exclude?
此外,如果您有3组测试,第一组是基本集,第二组和第三组是特殊情况,您是否可以使用配置文件进一步包含/排除? How will the profile include/exclude settings be merged?
如何合并配置文件包含/排除设置? For example, I would like to do something like this:
例如,我想做这样的事情:
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.12.2</version>
<configuration>
<excludes>
<exclude>/org/mycompany/dataset/test/ExtractProd*.java</exclude> <!-- requires special network connectivity -->
<exclude>/org/mycompany/dataset/test/LargeDataset*.java</exclude> <!-- requires lengthy processing -->
</excludes>
</configuration>
</plugin>
</plugins>
</build>
<profiles>
<profile>
<id>connectedToProdNetwork</id>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<includes>
<include>/org/mycompany/dataset/test/ExtractProd*.java</include>
</includes>
</configuration>
</plugin>
</plugins>
</build>
</profile>
<profile>
<id>runForAsLongAsYouNeed</id>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<includes>
<include>/org/mycompany/dataset/test/LargeDataset*.java</include>
</includes>
</configuration>
</plugin>
</plugins>
</build>
</profile>
</profiles>
And then be able to run like this: 然后能够像这样运行:
mvn package -P connectedToProdNetwork
or 要么
mvn package -P runForAsLongAsYouNeed
or 要么
mvn package -P connectedToProdNetwork,runForAsLongAsYouNeed
---- UPDATE ----- ----更新-----
Using mvn help:effective-pom -P [profileA]
I was able to determine that if i specify a single profile, the resulting effective pom will be: 使用
mvn help:effective-pom -P [profileA]
我能够确定如果我指定一个配置文件,那么产生的有效pom将是:
<configuration>
<includes>
<include>[includeFromProfileA]</include>
</includes>
<excludes>
<exclude>/org/mycompany/dataset/test/ExtractProd*.java</exclude> <!-- requires special network connectivity -->
<exclude>/org/mycompany/dataset/test/LargeDataset*.java</exclude> <!-- requires lengthy processing -->
</excludes>
</configuration>
And if I supply more than one profile, mvn help:effective-pom -P [profileA],[profileB]
: 如果我提供多个配置文件,
mvn help:effective-pom -P [profileA],[profileB]
:
<configuration>
<includes>
<include>[includeFromProfileAOrBSeeminglyArbitraryChoice]</include>
</includes>
<excludes>
<exclude>/org/mycompany/dataset/test/ExtractProd*.java</exclude> <!-- requires special network connectivity -->
<exclude>/org/mycompany/dataset/test/LargeDataset*.java</exclude> <!-- requires lengthy processing -->
</excludes>
</configuration>
And lastly, if I add the attribute combine.children="append"
to the <includes>
element of the profile configurations, and supply both profiles, mvn help:effective-pom -P [profileA],[profileB]
: 最后,如果我将属性
combine.children="append"
到配置文件配置的<includes>
元素,并提供两个配置文件, mvn help:effective-pom -P [profileA],[profileB]
:
<configuration>
<includes combine.children="append">
<include>[includeFromProfileA]</include>
<include>[includeFromProfileB]</include>
</includes>
<excludes>
<exclude>/org/mycompany/dataset/test/ExtractProd*.java</exclude> <!-- requires special network connectivity -->
<exclude>/org/mycompany/dataset/test/LargeDataset*.java</exclude> <!-- requires lengthy processing -->
</excludes>
</configuration>
However, now that each file is specified as both an <include>
and an <exclude>
, what happens? 但是,现在每个文件都被指定为
<include>
和<exclude>
,会发生什么?
---- UPDATE 2 ---- ----更新2 ----
Actually running a build with this configuration: 实际上使用此配置运行构建:
<configuration>
<includes>
<include>**/TestA.java</include>
</includes>
<excludes>
<exclude>**/TestA.java</exclude>
</excludes>
</configuration>
Does NOT run TestA, so it appears an <exclude>
will overpower an <include>
. 不运行TestA,因此看起来
<exclude>
会压倒<include>
。 Note that for completeness sake, I did reverse the order and put <excludes>
before <includes>
but the behavior did not change. 请注意,为了完整起见,我确实颠倒了顺序并在
<includes>
之前放置<excludes>
,但行为没有改变。 If anyone can find somewhere short of the source code where this behavior is outlined, I would be happy to give them the answer... 如果有人能找到这个行为概述的源代码之外的地方,我很乐意给他们答案......
I couldn't find official documentation about surefire plugin, but indeed the exclude-override-include is a common approach and is also applied by Maven in other similar contexts, like for resources. 我找不到关于surefire插件的官方文档,但实际上,exclude-override-include是一种常见方法,并且Maven也在其他类似的上下文中应用,例如资源。
The only official an related info (I found) comes from the official Maven POM Reference documentation, here : 唯一官方相关信息(我发现)来自官方Maven POM参考文档, 在这里 :
includes : A set of files patterns which specify the files to include as resources under that specified directory, using * as a wildcard.
includes :一组文件模式,使用*作为通配符,指定要包含在该指定目录下的资源的文件。
excludes : The same structure as includes, but specifies which files to ignore.
排除 :与includes相同的结构,但指定要忽略的文件。 In conflicts between include and exclude, exclude wins .
在包含和排除之间的冲突中,排除胜利 。
NOTE: I added the final bold formatting on the interesting statement. 注意:我在有趣的声明中添加了最终的粗体格式。
So more than probably the same approach is used across official maven plugins (in general, all the plugins having the org.apache.maven.plugins groupId and maven- prefix as artifactId). 因此,可能在官方maven插件中使用相同的方法(通常,所有插件都具有org.apache.maven.plugins groupId和maven-前缀作为artifactId)。
Have you tried using JUnit categories? 您是否尝试过使用JUnit类别?
http://www.agile-engineering.net/2012/04/unit-and-integration-tests-with-maven.html http://www.agile-engineering.net/2012/04/unit-and-integration-tests-with-maven.html
Using that approach, you could give tests a number of different categories, and exclude/include them using that, rather than the class name. 使用该方法,您可以为测试提供许多不同的类别,并使用它来排除/包含它们,而不是类名。 This would be a more extensible approach.
这将是一种更具扩展性的方法。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.