Post Mule 中的部署集成测试
Post Deployment Integration Testing in Mule
我有一个应用程序,我有一个使用 Munit 编写的集成测试套件。我正在使用 Jenkins 将其部署到 CloudHub。
如何执行测试用例 post-部署?
有没有我可以使用或者可以使用 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>
有关如何在 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
参数的集成测试执行。
简而言之,您的构建应该执行如下操作:
- 运行 通过 MUnit 进行单元测试(
unit-test
在 test
阶段执行)
- 在 Cloudhub 上部署您的应用程序(
deploy
在 pre-integration-test
阶段执行
- 运行 通过 MUnit 进行集成测试(
it-test
在 integration-test
阶段执行)
- 从 Cloudhub 取消部署您的应用程序(
undeploy
在 post-integration-test
阶段执行
如果您不熟悉阶段和执行,请阅读 Introduction to the Build Lifecycle
我有一个应用程序,我有一个使用 Munit 编写的集成测试套件。我正在使用 Jenkins 将其部署到 CloudHub。
如何执行测试用例 post-部署?
有没有我可以使用或者可以使用 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>
有关如何在 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
参数的集成测试执行。
简而言之,您的构建应该执行如下操作:
- 运行 通过 MUnit 进行单元测试(
unit-test
在test
阶段执行) - 在 Cloudhub 上部署您的应用程序(
deploy
在pre-integration-test
阶段执行 - 运行 通过 MUnit 进行集成测试(
it-test
在integration-test
阶段执行) - 从 Cloudhub 取消部署您的应用程序(
undeploy
在post-integration-test
阶段执行
如果您不熟悉阶段和执行,请阅读 Introduction to the Build Lifecycle