首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在单个阶段多次运行exec-maven-plugin

在单个阶段多次运行exec-maven-plugin
EN

Stack Overflow用户
提问于 2012-02-10 16:58:42
回答 2查看 7.6K关注 0票数 7

我正在尝试测试一个客户机/服务器应用程序,并使用Maven来处理构建/测试/部署。要测试应用程序,我需要:

  1. 运行安装程序脚本(安装服务器),
  2. 启动一个启动命令(启动服务),
  3. 运行测试(maven-surefire-plugin),
  4. 停止服务,然后
  5. 卸载服务。

步骤1、2、4和5将使用maven-exec-plugin。第三步将使用maven-surefire-plugin。

问题是,所有5个步骤都将发生在“测试”阶段。Maven允许按特定顺序执行插件。可以使用多个条目多次运行exec-plugin。问题是,我需要在4个执行插件的执行过程中使用尽力而为的插件。

以前有没有人遇到过这种情况,或者知道如何构造插件和执行程序?

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 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中执行。

代码语言:javascript
复制
<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>
票数 5
EN

Stack Overflow用户

发布于 2012-02-13 15:43:35

这就是我如何配置exec和故障安全插件的方式。我使用的是故障安全,而不是重新配置尽是火,因为肯定火仍然在运行其他测试处于测试阶段。这将在预集成测试阶段运行步骤1和步骤2(为同一阶段列出的多个执行将按照给定的顺序执行),在集成测试阶段运行测试,然后清理后集成测试阶段的步骤3和步骤4。

(注意:我有回显命令代替真正的安装和清理命令)

代码语言:javascript
复制
<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>
票数 10
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/9231626

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档