在一个阶段内多次运行execmaven插件
我正在尝试测试客户机/服务器应用程序,并使用Maven处理构建/测试/部署。要测试应用程序,我需要:在一个阶段内多次运行execmaven插件,maven,maven-2,maven-plugin,Maven,Maven 2,Maven Plugin,我正在尝试测试客户机/服务器应用程序,并使用Maven处理构建/测试/部署。要测试应用程序,我需要: 运行安装程序脚本(以安装服务器) 启动启动命令(启动服务) 运行测试(maven surefire插件) 停止服务,然后 卸载该服务 步骤1、2、4和5将使用maven exec插件。步骤3将使用maven surefire插件 问题是,所有这5个步骤都将发生在“测试”阶段。Maven允许插件按特定顺序执行。exec插件可以通过使用多个条目运行多次。问题是我需要在4个Excel插件执行的中间使用
以前是否有人遇到过这种情况,或者知道如何构造插件和执行?您试图做的事情听起来更像是集成测试而不是单元测试。对于该用例,有三个与集成测试相关的阶段:
:在执行集成测试之前执行所需的操作。这可能涉及设置所需环境等事项预集成测试
:如有必要,处理包并将其部署到可以运行集成测试的环境中集成测试
:执行集成测试后执行所需的操作。这可能包括清理环境集成后测试
<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>
org.apache.maven.plugins
maven surefire插件
真的
当然可以
集成测试
测试
假的
我就是这样配置exec和故障保护插件的。我使用的是故障保护,而不是重新配置surefire,因为surefire仍在运行其他处于测试阶段的测试。这将在预集成测试阶段运行步骤1和2(同一阶段的多个执行将按给定顺序执行),在集成测试阶段运行测试,然后在后集成测试阶段使用步骤3和4进行清理
(注意:我使用echo命令代替实际的安装和清理命令)
org.apache.maven.plugins
maven故障保护插件
集成测试
总是
org.codehaus.mojo
execmaven插件
步骤1
执行官
预集成测试
回声
福
步骤二
执行官
预集成测试
回声
酒吧
步骤三
执行官
整合后测试
回声
巴兹
步骤四
执行官
整合后测试
回声
胡特
我认为,您无法优化它maven surefire插件
+maven surefire插件
+maven exec插件
是你唯一能做到的方法(除非你有足够的勇气编写自己的maven插件,为你实现这一点)。这或多或少是我走的路线。我不知道为什么Maven缺少测试前和测试后阶段,但是使用集成测试阶段就足够了。这个插件的版本是什么?在版本1.2.1中,我无法让插件在内部执行
<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>