java maven-surefire-plugin 包含/排除优先级
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/11959211/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
maven-surefire-plugin include/exclude precedence
提问by Lucas
When using the maven-surefire-plugin and both includes and excludes, which order are they processed in? 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? How will the profile include/exclude settings be merged? For example, I would like to do something like this:
当使用 maven-surefire-plugin 并且包含和排除时,它们的处理顺序是什么?此外,如果您有 3 组测试,第一组是基本组,第二组和第三组是特殊情况,您是否可以使用配置文件进一步包含/排除?配置文件包含/排除设置将如何合并?例如,我想做这样的事情:
<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?
但是,既然每个文件都被指定为 an<include>
和 an <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 NOTrun TestA, so it appears an <exclude>
will overpower an <include>
. Note that for completeness sake, I did reverse the order and put <excludes>
before <includes>
but the behavior did not change.If anyone can find somewhere short of the source code where this behavior is outlined, I would be happy to give them the answer...
难道不运行外种皮,因此它的出现<exclude>
将压倒的<include>
。 请注意,为了完整起见,我确实颠倒了顺序并放在了<excludes>
之前,<includes>
但行为没有改变。如果有人能找到概述这种行为的源代码之外的地方,我很乐意给他们答案......
回答by A_Di-Matteo
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.
excludes: The same structure as includes, but specifies which files to ignore. In conflicts between include and exclude, exclude wins.
包括:一组文件模式,使用 * 作为通配符,指定要在该指定目录下作为资源包含的文件。
excludes:与包含的结构相同,但指定要忽略的文件。在 include 和 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)。
回答by johnmmcparland
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.
使用这种方法,您可以为测试提供许多不同的类别,并使用它而不是类名来排除/包含它们。这将是一种更可扩展的方法。