如何在 运行 junit4 集成测试之前通过 maven 部署 war?
How to deploy a war via maven before running junit4 integration tests?
我希望 Maven 在 运行 进行 jUnit 测试之前部署 war。
我已经添加了故障安全插件和配置,但部署在测试后仍然完成。
测试不是由故障安全插件 运行 进行的吗?
<build>
<finalName>testWar</finalName>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
<version>2.16</version>
<configuration>
<systemPropertyVariables>
<wildfly.remote.port>10090</wildfly.remote.port>
</systemPropertyVariables>
</configuration>
<executions>
<execution>
<goals>
<goal>integration-test</goal>
<goal>verify</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.wildfly.plugins</groupId>
<artifactId>wildfly-maven-plugin</artifactId>
<version>1.2.1.Final</version>
<configuration>
<hostname>host</hostname>
<port>10090</port>
<username>user</username>
<password>pw</password>
</configuration>
<executions>
<execution>
<id>wildfly-run</id>
<phase>pre-integration-test</phase>
<goals>
<goal>deploy</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
您报告的行为表明您的测试 运行 在 test
阶段而不是 integration-test
阶段。这是因为默认情况下,Maven Surefire 和 Maven Failsafe 插件都使用 class 名称约定来区分两种类型的测试,如下所述:
默认单元测试行为
Maven Surefire Plugin runs unit tests in the test
phase. By default it selects tests to execute based on the class name of the test, as described in Maven Surefire Plugin | Inclusions and Exclusions of Tests:
- "**/Test*.java" - 包括其所有子目录和所有以 "Test".
开头的 Java 文件名
- "**/*Test.java" - 包括其所有子目录和所有 Java 以 "Test".
结尾的文件名
- "**/*Tests.java" - 包括其所有子目录和所有 Java 以 "Tests".
结尾的文件名
- "**/*TestCase.java" - 包括其所有子目录和所有 Java 以 "TestCase".
结尾的文件名
默认集成测试行为
Maven Failsafe Plugin runs integration tests tests in the integration-test
phase. By default it also selects tests to execute based on the class name of the test, as described in [Maven Failsafe Plugin | Inclusions and Exclusions of Tests](https://maven.apache.org/surefire/maven-failsafe-plugin/examples/inclusion-exclusion.html:
- "**/IT*.java" - 包括其所有子目录和所有 Java 以 "IT".
开头的文件名
- "**/*IT.java" - 包括其所有子目录和所有 Java 以 "IT".
结尾的文件名
- "**/*ITCase.java" - 包括其所有子目录和所有 Java 以 "ITCase".
结尾的文件名
因此您可能只需要重命名您的集成测试 classes 以符合上面显示的三个约定之一。
我希望 Maven 在 运行 进行 jUnit 测试之前部署 war。
我已经添加了故障安全插件和配置,但部署在测试后仍然完成。
测试不是由故障安全插件 运行 进行的吗?
<build>
<finalName>testWar</finalName>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
<version>2.16</version>
<configuration>
<systemPropertyVariables>
<wildfly.remote.port>10090</wildfly.remote.port>
</systemPropertyVariables>
</configuration>
<executions>
<execution>
<goals>
<goal>integration-test</goal>
<goal>verify</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.wildfly.plugins</groupId>
<artifactId>wildfly-maven-plugin</artifactId>
<version>1.2.1.Final</version>
<configuration>
<hostname>host</hostname>
<port>10090</port>
<username>user</username>
<password>pw</password>
</configuration>
<executions>
<execution>
<id>wildfly-run</id>
<phase>pre-integration-test</phase>
<goals>
<goal>deploy</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
您报告的行为表明您的测试 运行 在 test
阶段而不是 integration-test
阶段。这是因为默认情况下,Maven Surefire 和 Maven Failsafe 插件都使用 class 名称约定来区分两种类型的测试,如下所述:
默认单元测试行为
Maven Surefire Plugin runs unit tests in the test
phase. By default it selects tests to execute based on the class name of the test, as described in Maven Surefire Plugin | Inclusions and Exclusions of Tests:
- "**/Test*.java" - 包括其所有子目录和所有以 "Test". 开头的 Java 文件名
- "**/*Test.java" - 包括其所有子目录和所有 Java 以 "Test". 结尾的文件名
- "**/*Tests.java" - 包括其所有子目录和所有 Java 以 "Tests". 结尾的文件名
- "**/*TestCase.java" - 包括其所有子目录和所有 Java 以 "TestCase". 结尾的文件名
默认集成测试行为
Maven Failsafe Plugin runs integration tests tests in the integration-test
phase. By default it also selects tests to execute based on the class name of the test, as described in [Maven Failsafe Plugin | Inclusions and Exclusions of Tests](https://maven.apache.org/surefire/maven-failsafe-plugin/examples/inclusion-exclusion.html:
- "**/IT*.java" - 包括其所有子目录和所有 Java 以 "IT". 开头的文件名
- "**/*IT.java" - 包括其所有子目录和所有 Java 以 "IT". 结尾的文件名
- "**/*ITCase.java" - 包括其所有子目录和所有 Java 以 "ITCase". 结尾的文件名
因此您可能只需要重命名您的集成测试 classes 以符合上面显示的三个约定之一。