maven - Mule 中的部署后集成测试

标签 maven testing mule integration munit

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

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

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

最佳答案

您可以配置您的 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>

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

编辑:当您使用 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 类(class)。

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

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

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

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

关于maven - Mule 中的部署后集成测试,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47015489/

相关文章:

java - 在 Eclipse 中部署到 Tomcat 时排除 svn 目录

java - 如何使用 Eclipse 中的资源从 Maven 项目创建可运行的 jar

php - 尝试在我的 Drupal 项目上运行 PhpUnit 测试时出现此错误

ruby-on-rails - 哪些 URL/路径可作为 Rails 5 中的局部变量进行测试?

java - 从自定义转换器访问 Mule 全局变量

java - liquibase 中的 SQL 文件从未执行过

java - Android studio gradle .pom文件下载报错

testing - JMeter 线程属性说明

java - Mule 使用什么类来发送 JMS 消息(端点)

java - "mule4 SFTP write connector writing file with timestamp , move connector unable to fetch filename from different flow"