【问题标题】:Post Deployment Integration Testing in MuleMule 中的部署后集成测试
【发布时间】:2018-04-11 10:43:22
【问题描述】:

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

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

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

【问题讨论】:

  • 我刚刚意识到我的回答可能不合适。您说您正在通过 Jenkins 将您的应用程序部署到 CloudHub,所以您的意思是您想在 CloudHub 上的 Jenkins 部署之后立即运行集成测试?如果是这样,您目前如何使用 Jenkins 在 CloudHub 上进行部署? (使用 Maven,脚本,还有什么?)
  • 如果您的项目当前使用 Maven 来完成这些任务,最好包含您的 pom.xml

标签: maven testing mule integration munit


【解决方案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 正则表达式匹配的测试。

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

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

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

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

如果您不熟悉阶段和执行,请阅读Introduction to the Build Lifecycle

【讨论】:

  • 感谢皮埃尔的回答。我们如何在 Anypoint Studio 中尝试这个?
  • 要使用 Maven 启动集成测试,最好的方法是运行 mvn clean verify 命令。当您使用 MUnit 时,您应该在 pom.xml 中包含 Munit Maven 插件的正确 MUnit 配置 - 我在回答中遗漏了一些内容,我将对其进行编辑。但是我不知道使用 Eclipse 或 Studio 运行集成测试的任何实用方法,通常只有单元测试通过 IDE 运行。最好使用终端或 shell,或者通过 Jenkins,就像您可能已经在做的那样。
  • 感谢 Pierre 的即时帮助。
  • 是的,我正在使用 Jenkins 在云中心部署它。正如你所说,我可以使用命令行运行测试。另外,我需要更多帮助,如何在进行集成测试时测试 munit 中的网络连接性。
  • 如果我有 AMQP 连接器,我想测试它可用和不可用时的行为。如果您为此共享任何示例测试脚本,那将是一个很大的帮助。我不想模拟我想实时测试的行为。
猜你喜欢
  • 1970-01-01
  • 2023-03-18
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-11-03
  • 1970-01-01
相关资源
最近更新 更多