Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/maven/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Maven Mule中的部署后集成测试_Maven_Testing_Mule_Integration_Munit - Fatal编程技术网

Maven Mule中的部署后集成测试

Maven Mule中的部署后集成测试,maven,testing,mule,integration,munit,Maven,Testing,Mule,Integration,Munit,我有一个应用程序,我有一个使用Munit编写的集成测试套件。我正在使用Jenkins将其部署到CloudHub 部署后如何执行测试用例 是否有任何命令行工具可供我使用,或者可以使用maven或Jenkins来完成?您可以将maven构建配置为在集成前测试阶段部署Mule应用程序,在集成测试阶段运行测试,并可以在集成后测试阶段取消部署。您可以使用以下内容: <plugins> ... <plugin> <groupId>org

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

部署后如何执行测试用例


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

您可以将maven构建配置为在集成前测试阶段部署Mule应用程序,在集成测试阶段运行测试,并可以在集成后测试阶段取消部署。您可以使用以下内容:

<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上配置部署的详细信息,请参阅

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

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

配置了两个执行:

第一个将在测试阶段运行,并通过munitest参数仅使用与.*-unit-test-suite.xml正则表达式匹配的MUnit测试 第二个将在集成测试上运行,并且只使用与.*-integration-test-suite.xml正则表达式匹配的测试。 然后,您必须根据这些模式命名单元测试和集成测试,以确保它们以正确的顺序启动。当然,这是一个例子,重要的是确保您的单元测试和集成测试是不同的,并在适当的时候启动——就像Maven Failsafe和Surefire插件分别使用*Test和*it类所做的那样

如果只有集成测试要运行,则可以跳过此复杂配置,只使用集成测试执行,而不使用munitest参数

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

<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>
在测试阶段,通过MUnit单元测试执行运行单元测试 在预集成测试阶段,在Cloudhub部署执行上部署应用程序 在集成测试阶段,通过MUnit it测试执行运行集成测试 从Cloudhub取消部署应用程序在集成后测试阶段取消部署执行
如果您不熟悉阶段和执行,请阅读

谢谢您的回答。我们如何在Anypoint Studio中尝试这一点?要使用Maven启动集成测试,最好的方法是运行mvn clean verify命令。在使用MUnit时,您应该在pom.xml中为MUnit Maven插件包含一个适当的MUnit配置—我在回答中遗漏了这一点,我将对其进行编辑。然而,我不知道使用Eclipse或Studio运行集成测试的任何实际方法,通常只有单元测试通过IDE运行。最好使用终端或外壳,或者通过Jenkins,正如您可能已经在做的那样。感谢Pierre的即时帮助。是的,我正在使用Jenkins在cloud hub中部署此功能。正如您所说,我可以使用命令行运行测试。此外,我还需要一个帮助,如何在进行集成测试时测试munit中的网络连接。如果我使用AMQP连接器,我希望在其可用和不可用时测试其行为。如果你能分享一些测试脚本的例子,那将是一个很大的帮助。我不想嘲笑这种行为,我想实时测试它。我只是意识到我的答案可能不合适。你说你要通过Jenkins将你的应用程序部署到CloudHub,那么你的意思是你想在Jenkins部署到CloudHub之后立即运行集成测试?如果是这样,您目前如何与Jenkins一起在CloudHub上部署?使用Maven、脚本或其他任何东西?如果您的项目当前使用Maven执行任何这些任务,那么最好包含pom.xml