我有一个应用程序,我有一个使用Munit编写的集成测试套件。我正在使用Jenkins将其部署到CloudHub。
如何在部署后执行测试用例?
是否有任何可以使用的命令行工具,或者可以使用maven或Jenkins完成?
答案 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
参数的集成测试执行。
简而言之,您的构建应该执行以下操作:
unit-test
阶段test
执行)deploy
阶段执行pre-integration-test
it-test
阶段integration-test
执行)undeploy
期间执行post-integration-test
如果您不熟悉阶段和执行情况,请阅读Introduction to the Build Lifecycle