为什么 failsafe: not executed with "mvn verify"?
Why is failsafe: not executed with "mvn verify"?
为什么"failsafe:integration-test"不会自动执行mvn verify
?
根据 mvn help:describe ...
,maven-failsafe-plugin
任务 "integraton-test" 应该绑定到 "integration-test" 阶段:
failsafe:integration-test
Description: Run integration tests using Surefire.
Implementation: org.apache.maven.plugin.failsafe.IntegrationTestMojo
Language: java
Bound to phase: integration-test
然而 mvn verify
只执行 "surefire:test" 而不是 "failsafe:integration-test".
我知道如何使用 <executions>
解决这个问题,因为即使在故障安全插件主页上的 "Usage" 示例中也是如此,但我想了解为什么这两个插件的行为不同。
有文件同时匹配 <include>
模式:
src/test/java/de/lathspell/test/UselessThingTest.java
src/test/java/de/lathspell/test/UselessThingIT.java
我的 pom.xml 看起来像这样:
<?xml version="1.0" encoding="UTF-8"?>
<project
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:pom="http://maven.apache.org/POM/4.0.0">
<modelVersion>4.0.0</modelVersion>
<groupId>de.lathspell</groupId>
<artifactId>test1</artifactId>
<version>0.0.1-SNAPSHOT</version>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<build>
<plugins>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.22.1</version>
</plugin>
<plugin>
<artifactId>maven-failsafe-plugin</artifactId>
<version>2.22.1</version>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>
输出:
[INFO] -------------------------< de.lathspell:test1 >-------------------------
[INFO] Building test1 0.0.1-SNAPSHOT
[INFO] --------------------------------[ jar ]---------------------------------
[INFO]
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ test1 ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] skip non existing resourceDirectory /mnt/keller_christian/workspace/test1/src/main/resources
[INFO]
[INFO] --- maven-compiler-plugin:3.1:compile (default-compile) @ test1 ---
[INFO] Nothing to compile - all classes are up to date
[INFO]
[INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) @ test1 ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] skip non existing resourceDirectory /mnt/keller_christian/workspace/test1/src/test/resources
[INFO]
[INFO] --- maven-compiler-plugin:3.1:testCompile (default-testCompile) @ test1 ---
[INFO] Nothing to compile - all classes are up to date
[INFO]
[INFO] --- maven-surefire-plugin:2.22.1:test (default-test) @ test1 ---
[INFO]
[INFO] -------------------------------------------------------
[INFO] T E S T S
[INFO] -------------------------------------------------------
[INFO] Running de.lathspell.test.UselessThingTest
[INFO] Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.048 s - in de.lathspell.test.UselessThingTest
[INFO]
[INFO] Results:
[INFO]
[INFO] Tests run: 1, Failures: 0, Errors: 0, Skipped: 0
[INFO]
[INFO]
[INFO] --- maven-jar-plugin:2.4:jar (default-jar) @ test1 ---
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
简单的事情是 maven-failsafe-plugin 默认情况下不绑定任何类型的生命周期。
这意味着您必须自己在项目中绑定一次。
文档说:
Binds by default to the lifecycle phase: integration-test.
这意味着您必须完全添加到生命周期,然后插件将绑定到 integration-test
生命周期。
<project>
[...]
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
<version>3.0.0-M3</version>
<executions>
<execution>
<goals>
<goal>integration-test</goal>
<goal>verify</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
[...]
</project>
在此之后,您应该使用以下命令简单地执行集成测试:
mvn clean verify
更新:
如果插件的文档说:
Binds by default to the lifecycle phase: x
这意味着如果你像上面那样添加一个执行,它只绑定到给定的生命周期阶段但是还没有定义<phase>..</phaseY>
。这是一种你没有在你的 pom 配置中明确给出的默认值。
为什么"failsafe:integration-test"不会自动执行mvn verify
?
根据 mvn help:describe ...
,maven-failsafe-plugin
任务 "integraton-test" 应该绑定到 "integration-test" 阶段:
failsafe:integration-test
Description: Run integration tests using Surefire.
Implementation: org.apache.maven.plugin.failsafe.IntegrationTestMojo
Language: java
Bound to phase: integration-test
然而 mvn verify
只执行 "surefire:test" 而不是 "failsafe:integration-test".
我知道如何使用 <executions>
解决这个问题,因为即使在故障安全插件主页上的 "Usage" 示例中也是如此,但我想了解为什么这两个插件的行为不同。
有文件同时匹配 <include>
模式:
src/test/java/de/lathspell/test/UselessThingTest.java
src/test/java/de/lathspell/test/UselessThingIT.java
我的 pom.xml 看起来像这样:
<?xml version="1.0" encoding="UTF-8"?>
<project
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:pom="http://maven.apache.org/POM/4.0.0">
<modelVersion>4.0.0</modelVersion>
<groupId>de.lathspell</groupId>
<artifactId>test1</artifactId>
<version>0.0.1-SNAPSHOT</version>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<build>
<plugins>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.22.1</version>
</plugin>
<plugin>
<artifactId>maven-failsafe-plugin</artifactId>
<version>2.22.1</version>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>
输出:
[INFO] -------------------------< de.lathspell:test1 >-------------------------
[INFO] Building test1 0.0.1-SNAPSHOT
[INFO] --------------------------------[ jar ]---------------------------------
[INFO]
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ test1 ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] skip non existing resourceDirectory /mnt/keller_christian/workspace/test1/src/main/resources
[INFO]
[INFO] --- maven-compiler-plugin:3.1:compile (default-compile) @ test1 ---
[INFO] Nothing to compile - all classes are up to date
[INFO]
[INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) @ test1 ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] skip non existing resourceDirectory /mnt/keller_christian/workspace/test1/src/test/resources
[INFO]
[INFO] --- maven-compiler-plugin:3.1:testCompile (default-testCompile) @ test1 ---
[INFO] Nothing to compile - all classes are up to date
[INFO]
[INFO] --- maven-surefire-plugin:2.22.1:test (default-test) @ test1 ---
[INFO]
[INFO] -------------------------------------------------------
[INFO] T E S T S
[INFO] -------------------------------------------------------
[INFO] Running de.lathspell.test.UselessThingTest
[INFO] Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.048 s - in de.lathspell.test.UselessThingTest
[INFO]
[INFO] Results:
[INFO]
[INFO] Tests run: 1, Failures: 0, Errors: 0, Skipped: 0
[INFO]
[INFO]
[INFO] --- maven-jar-plugin:2.4:jar (default-jar) @ test1 ---
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
简单的事情是 maven-failsafe-plugin 默认情况下不绑定任何类型的生命周期。
这意味着您必须自己在项目中绑定一次。
文档说:
Binds by default to the lifecycle phase: integration-test.
这意味着您必须完全添加到生命周期,然后插件将绑定到 integration-test
生命周期。
<project>
[...]
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
<version>3.0.0-M3</version>
<executions>
<execution>
<goals>
<goal>integration-test</goal>
<goal>verify</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
[...]
</project>
在此之后,您应该使用以下命令简单地执行集成测试:
mvn clean verify
更新: 如果插件的文档说:
Binds by default to the lifecycle phase: x
这意味着如果你像上面那样添加一个执行,它只绑定到给定的生命周期阶段但是还没有定义<phase>..</phaseY>
。这是一种你没有在你的 pom 配置中明确给出的默认值。