1

我按照教程安装 MUnit 插件作为这个页面:https ://docs.mulesoft.com/munit/v/1.1.1/using-munit-in-anypoint-studio

但是,当我运行一个空的测试用例时,AnyPoint 向我返回一个错误:发生 JNI 错误,请检查您的安装并重试。

在控制台中,我看到异常为:

线程“main”中的异常 java.lang.NoClassDefFoundError: org/mule/munit/runner/mule/result/notification/NotificationListener at java.lang.Class.getDeclaredMethods0(Native Method) at java.lang.Class.privateGetDeclaredMethods(Unknown Source ) 在 java.lang.Class.privateGetMethodRecursive(Unknown Source) 在 java.lang.Class.getMethod0(Unknown Source) 在 java.lang.Class.getMethod(Unknown Source) 在 sun.launcher.LauncherHelper.validateMainClass(Unknown Source) 在sun.launcher.LauncherHelper.checkAndLoadMain(Unknown Source) 引起:java.lang.ClassNotFoundException: org.mule.munit.runner.mule.result.notification.NotificationListener at java.net.URLClassLoader.findClass(Unknown Source) at java. lang.ClassLoader.loadClass(Unknown Source) at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source) at java.lang.ClassLoader。loadClass(Unknown Source) ... 7 更多

请帮助检查是什么问题。

提前致谢。

4

2 回答 2

2

我在这里假设一些事情:1)您正在使用 Anypoint Studio 和 2)您的项目是 Mavenized

1) 安装 MUnit:转到 Anypoint Studio 中的帮助菜单,然后单击安装新软件。在Work With列中输入http://studio.mulesoft.org/r4/munit并添加。

完成后,我们需要将此 MUnit 添加到 Maven 路径。

2) 添加到路径:在您的项目资源管理器中,转到src/test/munit并右键单击它。从下拉菜单中选择Munit并选择Configure MUnit Maven Support

在此之后,Maven 将自动触发构建,并且将下载所有必要的文件,包括您在问题中提到的文件。

希望这可以帮助!

于 2017-08-22T06:09:39.467 回答
0

您可能在运行时没有 MUnit 运行器。您可以通过将 munit runner 添加到我的 pom.xml 来解决此问题。

依赖

<dependency>
<groupId>com.mulesoft.munit</groupId>
<artifactId>mule-munit-support</artifactId>
<version>${mule.munit.support.version}</version>
<scope>test</scope>

<dependency>
<groupId>com.mulesoft.munit</groupId>
<artifactId>munit-runner</artifactId>
<version>${munit.version}</version>
<scope>test</scope>

插入

<plugin>
            <groupId>com.mulesoft.munit.tools</groupId>
            <artifactId>munit-maven-plugin</artifactId>
            <version>${munit.version}</version>
            <executions>
                <execution>
                    <id>test</id>
                    <phase>test</phase>
                    <goals>
                        <goal>test</goal>
                    </goals>
                </execution>
            </executions>
            <configuration>
                <coverage>
                    <runCoverage>true</runCoverage>
                    <formats>
                        <format>html</format>
                    </formats>
                </coverage>
            </configuration>
        </plugin>

还要记住将您的 munit 源添加为 maven 测试资源,例如,

<testResources>
        <testResource>
            <directory>src/test/munit</directory>
        </testResource>
    <testResource>
            <directory>src/test/resources</directory>
        </testResource>
    </testResources
于 2019-01-28T16:20:29.260 回答