我正在尝试测试一个客户机/服务器应用程序,并使用Maven来处理构建/测试/部署。要测试应用程序,我需要:
步骤1、2、4和5将使用maven-exec-plugin。第三步将使用maven-surefire-plugin。
问题是,所有5个步骤都将发生在“测试”阶段。Maven允许按特定顺序执行插件。可以使用多个条目多次运行exec-plugin。问题是,我需要在4个执行插件的执行过程中使用尽力而为的插件。
以前有没有人遇到过这种情况,或者知道如何构造插件和执行程序?
发布于 2012-02-11 16:11:06
您想要做的事情听起来更像是集成测试,而不是单元测试。对于这个用例,默认maven生命周期有三个与集成测试相关的阶段:
pre-integration-test:在执行集成测试之前执行所需的操作。这可能涉及诸如设置所需的环境之类的事情。integration-test:必要时将包处理并部署到可以运行集成测试的环境中。post-integration-test:在执行集成测试之后执行所需的操作。这可能包括清理环境。默认插件通常在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>发布于 2012-02-13 15:43:35
这就是我如何配置exec和故障安全插件的方式。我使用的是故障安全,而不是重新配置尽是火,因为肯定火仍然在运行其他测试处于测试阶段。这将在预集成测试阶段运行步骤1和步骤2(为同一阶段列出的多个执行将按照给定的顺序执行),在集成测试阶段运行测试,然后清理后集成测试阶段的步骤3和步骤4。
(注意:我有回显命令代替真正的安装和清理命令)
<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>https://stackoverflow.com/questions/9231626
复制相似问题