Sli*_*ole 7 maven-2 maven-plugin maven
我正在尝试测试客户端/服务器应用程序,并使用Maven来处理构建/测试/部署.要测试应用程序,我需要:
步骤1,2,4和5将使用maven-exec-plugin.第3步将使用maven-surefire-plugin.
问题是所有这5个步骤都将在"测试"阶段发生.Maven允许以特定顺序执行插件.exec-plugin可以使用多个条目多次运行.问题是我需要在4个exec-plugin执行的中间使用surefire-plugin.
有没有人曾经遇到过这个,或者知道如何构建插件和执行的?
Sli*_*ole 10
这就是我配置exec和failafe插件的方式.我正在使用故障保护,而不是重新配置surefire,因为surefire仍在运行其他测试以进入测试阶段.这将在预集成测试阶段运行步骤1和2(为同一阶段列出的多个执行将按给定的顺序执行),在集成测试阶段运行测试,然后使用步骤3和4清理后整合测试阶段.
(注意:我有echo命令代替真正的安装和清理命令)
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>integration-test</goal>
</goals>
</execution>
</executions>
<configuration>
<forkMode>always</forkMode>
</configuration>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<executions>
<execution>
<id>step1</id>
<goals>
<goal>exec</goal>
</goals>
<phase>pre-integration-test</phase>
<configuration>
<executable>echo</executable>
<arguments>
<argument>foo</argument>
</arguments>
</configuration>
</execution>
<execution>
<id>step2</id>
<goals>
<goal>exec</goal>
</goals>
<phase>pre-integration-test</phase>
<configuration>
<executable>echo</executable>
<arguments>
<argument>bar</argument>
</arguments>
</configuration>
</execution>
<execution>
<id>step3</id>
<goals>
<goal>exec</goal>
</goals>
<phase>post-integration-test</phase>
<configuration>
<executable>echo</executable>
<arguments>
<argument>baz</argument>
</arguments>
</configuration>
</execution>
<execution>
<id>step4</id>
<goals>
<goal>exec</goal>
</goals>
<phase>post-integration-test</phase>
<configuration>
<executable>echo</executable>
<arguments>
<argument>woot</argument>
</arguments>
</configuration>
</execution>
</executions>
</plugin>
Run Code Online (Sandbox Code Playgroud)
您尝试做的事情听起来更像是集成测试而不是单元测试。对于此用例,默认的 Maven 生命周期具有与集成测试相关的三个阶段:
pre-integration-test:在执行集成测试之前执行所需的操作。这可能涉及诸如设置所需环境之类的事情。integration-test:如有必要,处理包并将其部署到可以运行集成测试的环境中。post-integration-test:执行集成测试后执行所需的操作。这可能包括清理环境。Surefire 插件通常在该test阶段执行,但可以重新配置为在另一个阶段执行。然后可以将步骤 1 + 2 配置为在 中执行pre-integration-test,而步骤 4 + 5 必须在 中执行post-integration-test。
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<!-- Skip execution in test phase and execute in integration-test phase instead -->
<configuration>
<skip>true</skip>
</configuration>
<executions>
<execution>
<id>surefire-it</id>
<phase>integration-test</phase>
<goals>
<goal>test</goal>
</goals>
<configuration>
<skip>false</skip>
</configuration>
</execution>
</executions>
</plugin>
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
6686 次 |
| 最近记录: |