一、异常描述
运行springMVC的项目通过spring-test的org.springframework.test.context.junit4.AbstractJUnit4SpringContextTests进行单元测试调试,运行报"java.lang.NoClassDefFoundError: org/junit/runners/model/MultipleFailureException..Caused by: java.lang.ClassNotFoundException: org.junit.runners.model.MultipleFailureException.."错误异常,详情如下日志所示>>
java.lang.NoClassDefFoundError: org/junit/runners/model/MultipleFailureException@b@ at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.withAfterClasses(SpringJUnit4ClassRunner.java:188)@b@ at org.junit.runners.ParentRunner.classBlock(ParentRunner.java:145)@b@ at org.junit.runners.ParentRunner.run(ParentRunner.java:235)@b@ at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.run(SpringJUnit4ClassRunner.java:163)@b@ at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:49)@b@ at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)@b@ at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)@b@ at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)@b@ at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)@b@ at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)@b@Caused by: java.lang.ClassNotFoundException: org.junit.runners.model.MultipleFailureException@b@ at java.net.URLClassLoader$1.run(URLClassLoader.java:366)@b@ at java.net.URLClassLoader$1.run(URLClassLoader.java:355)@b@ at java.security.AccessController.doPrivileged(Native Method)@b@ at java.net.URLClassLoader.findClass(URLClassLoader.java:354)@b@ at java.lang.ClassLoader.loadClass(ClassLoader.java:425)@b@ at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)@b@ at java.lang.ClassLoader.loadClass(ClassLoader.java:358)@b@ ... 10 more
二、解决方法
1. 如下图在项目中引入JUnit4依赖库
2. 下载引入对应junit的ar版本(如本项目的junit-4.12.jar版本)导入项目Libraires即可解决问题。