0

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

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

有没有我可以使用的命令行工具,或者可以使用 maven 或 Jenkins 来完成?

4

1 回答 1

1

您可以配置您的 Maven 构建以在该阶段部署您的 Mule 应用程序,在该pre-integration-test阶段运行您的测试,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 插件文档。

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

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

配置了 2 个执行:

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

然后,您必须根据这些模式命名您的单元测试和集成测试,以确保它们以正确的顺序启动。这当然是一个例子,重要的是确保你的单元测试和集成测试是有区别的并在适当的时候启动——因为它是通过分别使用 Maven Failsafe 和 Surefire 插件*Test*IT类来完成的。

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

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

  1. 通过 MUnit 运行单元测试(unit-testtest阶段执行)
  2. 在 Cloudhub 上部署您的应用程序(deploypre-integration-test阶段执行
  3. 通过 MUnit 运行集成测试(it-testintegration-test阶段执行)
  4. 从 Cloudhub 取消部署您的应用程序(undeploypost-integration-test阶段执行

如果您不熟悉阶段和执行,请阅读构建生命周期简介

于 2017-10-31T09:54:13.313 回答