when you use JUnit for unit testing, you suddenly receive the following error:
Java.lang.noclassdeffounderror:org/hamcrest/selfdescribing at Java.lang.ClassLoader.defineClass1 (Native method) a T Java.lang.ClassLoader.defineClassCond (classloader.java:631) at Java.lang.ClassLoader.defineClass ( classloader.java:615) at Java.security.SecureClassLoader.defineClass (secureclassloader.java:141) at Java.net.URLCl Assloader.defineclass (urlclassloader.java:283) at java.net.urlclassloader.access$000 (URLClassLoader.java:58) at Ja Va.net.urlclassloader$1.run (urlclassloader.java:197) at Java.security.AccessController.doPrivileged (Native method ) at Java.net.URLClassLoader.findClass (urlclassloader.java:190) at Java.lang.ClassLoader.loadClass (Classloader.jav a:306) at Sun.misc.launcher$appclassloader.loadclass (launcher.java:301) at Java.lang.ClassLoader.loadClass (Classlo ader.java:247) at Org.junit.internal.builders.JUnit4Builder.runnerForClass (junit4builder.java:10) at Org.junit.run Ners.model.RunnerBuilder.safeRunnerForClass (Runnerbuilder.java:59) at Org.junit.internal.builders.AllDefaultPossibilitiesBuilder.runnerForClass ( alldefaultpossibilitiesbuilder.java:26) at Org.junit.runners.model.RunnerBuilder.safeRunnerForClass ( runnerbuilder.java:59) at Org.junit.internal.requests.ClassRequest.getRunner (classrequest.java:26) at Com.intellij . Junit4. Junit4ideatestrunner.startrunnerwithargs (junit4ideatestrunner.java:44) at Com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart (junitstarter.java:195) at Com.intellij.rt.execution.junit.JUnitStarter.main (junitstarter.java:63) at Sun.reflect.NativeMethodAccessorImpl.invoke0 (Native method) at Sun.reflect.NativeMethodAccessorImpl.invoke ( nativemethodaccessorimpl.java:39) at Com.intellij.rt.execution.application.AppMain.main (appmain.java:120) caused By:java.lang.ClassNotFoundException:org.hamcrest.SelfDescribing at Java.net.urlclassloader$1.run ( urlclassloader.java:202) at java.security.AccessController.doPrivileged (Native method in Java.net.URLClassLoader.findClass (urlclassloader.java:190) at Java.lang.ClassLoader.loadClass (Classl oader.java:306) at Sun.misc.launcher$appclassloader.loadclass (launcher.java:301) at Java.lang.ClassLoader.loadClas S (classloader.java:247) ... More
The reason for the error is that the Hamcrest-core-*.jar package is missing from the JUnit jar package used, download the jar package, import the project, and the problem will be solved naturally.