Mule中的部署后集成测试

时间:2017-10-30 12:37:28

标签: maven testing mule integration munit

我有一个应用程序,我有一个使用Munit编写的集成测试套件。我正在使用Jenkins将其部署到CloudHub。

如何在部署后执行测试用例?

是否有任何可以使用的命令行工具,或者可以使用maven或Jenkins完成?

1 个答案:

答案 0 :(得分:1)

您可以配置Maven构建以在pre-integration-test阶段部署Mule应用程序,在integration-test阶段运行测试,并在post-integration-test阶段可选择取消部署。你可以使用类似的东西:

<plugins>

    ...

    <plugin>
        <groupId>org.mule.tools.maven</groupId>
        <artifactId>mule-app-maven-plugin</artifactId>
        <version>1.1</version>
        <extensions>true</extensions>
    </plugin>
    <plugin>
        <groupId>org.mule.tools.maven</groupId>
        <artifactId>mule-maven-plugin</artifactId>
        <version>2.0</version>
        <configuration>
            <deploymentType>cloudhub</deploymentType>
            <!-- muleVersion is the runtime version as it appears on the CloudHub interface -->
            <muleVersion>3.7.0</muleVersion>
            <username>myUsername</username>
            <password>myPassword</password>
            <redeploy>true</redeploy>
            <environment>Production</environment>
        </configuration>
        <executions>
            <execution>
                <id>deploy</id>
                <phase>pre-integration-test</phase>
                <goals>
                    <goal>deploy</goal>
                </goals>
            </execution>
            <execution>
                <id>undeploy</id>
                <phase>post-integration-test</phase>
                <goals>
                    <goal>undeploy</goal>
                </goals>
            </execution>
        </executions>
    </plugin>
    <plugin>
            <groupId>com.mulesoft.munit.tools</groupId>
            <artifactId>munit-maven-plugin</artifactId>
            <version>${munit.version}</version>
            <executions>
                <execution>
                    <id>unit-test</id>
                    <phase>test</phase>
                    <goals>
                        <goal>test</goal>
                    </goals>
                    <configuration>
                        <munittest>.*-unit-test-suite.xml</munittest>
                    </configuration>
                </execution>
                <execution>
                    <id>it-test</id>
                    <phase>integration-test</phase>
                    <goals>
                        <goal>test</goal>
                    </goals>
                    <configuration>
                        <munittest>.*-integration-test-suite.xml</munittest>
                    </configuration>
                </execution>
            </executions>
            <configuration>
                <coverage>
                    <runCoverage>false</runCoverage>>
                </coverage>
            </configuration>
        </plugin>

    ...

</plugins>

有关如何在CloudHub上配置部署的详细信息,请参阅Mule Maven plugin documentation

编辑:当您使用MUnit运行测试时,您必须配置MUnit Maven插件来运行集成测试,并将它们与最终的单元测试区分开来。见MUnit Maven Support。您的MUnit集成测试应该在integration-test阶段运行。如果您在配置构建时遇到问题,请在评论中告诉我,我会相应地进行编辑。

EDIT2:我更新了我的答案,提供了一个能够执行单元测试和集成测试的MUnit Maven配置的工作示例。

已配置2个执行:

  • 第一个将在test阶段运行并仅使用与.*-unit-test-suite.xml正则表达式匹配的MUnit测试(通过munittest参数)
  • 第二个将在integration-test上运行并仅使用与.*-integration-test-suite.xml正则表达式匹配的测试。

然后,您必须根据这些模式命名单元测试和集成测试,以确保它们按正确的顺序启动。这当然是一个例子,重要的是确保您的单元测试和集成测试在适当的时刻进行区分和启动 - 分别使用Maven Failsafe和Surefire插件*Test*IT课程。

如果您只运行集成测试,则可以跳过此复杂配置,只使用不带munittest参数的集成测试执行。

简而言之,您的构建应该执行以下操作:

  1. 通过MUnit运行单元测试(unit-test阶段test执行)
  2. 在Cloudhub上部署您的应用程序(deploy阶段执行pre-integration-test
  3. 通过MUnit运行集成测试(it-test阶段integration-test执行)
  4. 从Cloudhub取消部署您的应用程序(undeploy期间执行post-integration-test
  5. 如果您不熟悉阶段和执行情况,请阅读Introduction to the Build Lifecycle