什么是“默认测试"?在maven-surefire插件中代表 [英] What does the "default-test" stand for in the maven-surefire plugin
问题描述
我在pom中为使用TestNg的surefire定义了以下配置:
I have defined the following configuration in my pom for surefire with TestNg:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.12</version>
<configuration>
<skipTests>${skip-all-tests}</skipTests>
</configuration>
<executions>
<execution>
<id>unit-tests</id>
<phase>test</phase>
<goals>
<goal>test</goal>
</goals>
<configuration>
<skip>${skip-unit-tests}</skip>
<groups>unit</groups>
<excludedGroups>integration</excludedGroups>
</configuration>
</execution>
<execution>
<id>integration-tests</id>
<phase>integration-test</phase>
<goals>
<goal>test</goal>
</goals>
<configuration>
<skip>${skip-integration-tests}</skip>
<groups>integration</groups>
<excludedGroups>unit</excludedGroups>
</configuration>
</execution>
</executions>
</plugin>
但是似乎这两个执行总是在"default-test"运行之前执行,该运行似乎在每个@test注释方法中运行(至少我认为是这样).
But it seems the two executions are always preceded by a "default-test" run which seems to run every @test annotated method (at least I think so).
--- maven-surefire-plugin:2.12:test (default-test) @ my-project
例如,在项目上运行"mvn test",将执行两次测试. 默认测试"和单元测试".
For example running "mvn test" on the project, two test executions take place. The "default-test" and the "unit-test".
有人可以向我解释一下吗? 可以禁用或控制此功能(配置测试内容而不配置什么功能)吗?
Could someone explain this a little more to me? Can this be disabled or controlled (configured what is tested and what not)?
推荐答案
人们希望有一种方法可以覆盖Maven中插件的默认内置执行.
People wanted to have a way to override the default built-in executions of plugins within Maven.
Maven 3(或者可能早于2.1.0或2.2.0引入)通过为包装生命周期添加到有效pom的每个插件执行定义默认执行ID来解决此问题.
Maven 3 (or it may have been introduced as early as 2.1.0 or 2.2.0) solved this by defining a default execution id for each plugin execution added to the effective pom by the packaging's lifecycle.
此隐式ID的名称始终为default-_____
,我无法回忆起为其生成的确切规则.
The name of this implicit id is always default-_____
I cannot recall the exact rule that it is generated for.
因此,您可以通过定义匹配的执行来覆盖包装的注入执行.
You can therefore override the packaging's injected executions by defining a matching execution.
要解决您的情况,我可以将<id>unit-tests</id>
更改为<id>default-test</id>
或
添加
To solve your case I would either change <id>unit-tests</id>
to <id>default-test</id>
or
add
<execution>
<id>default-test</id>
<configuration>
<skip>true</skip>
</configuration>
</execution>
尽管<id>unit-tests</id>
到<id>default-test</id>
解决方案的性能稍高,但您只需调用两次surefire执行,
都将具有相同的效果.
either will have the same effect, though the <id>unit-tests</id>
to <id>default-test</id>
solution will be slightly more performant as you only need to invoke two executions of surefire.
我要指出的另一件事是,您可能最好使用maven-failsafe-plugin执行集成测试,因为有时您可能想在&之前做一些事情.集成后测试,并且针对该用例设计了故障安全保护(尽管将其进一步切换到该用例上是微不足道的)
The other thing I would point out is you would probably be better off using maven-failsafe-plugin to execute your integration tests as at some point in time you may want to do some stuff pre & post integration testing, and failsafe is designed for that use case (though it should be trivial to switch further down the line)
这篇关于什么是“默认测试"?在maven-surefire插件中代表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!