JUnit4.12使用报java.lang.NoClassDefFoundError: org/hamcrest/SelfDescribing错误解决方法

从错误提示可以看出没有hamcrest包中的类

在这里插入图片描述
网上提供的方案
导入包的方案:junit.jar+ hamcrest-core.jar + hamcrest-library.jar
自己解决成功方案:在有junit-4.12.jar的情况下,导入hamcrest-core-1.3.jar便可以成功运行了。
maven项目可以:

<dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>4.12</version>
      <scope>test</scope>
</dependency>
<!-- junit包 -->
<dependency>
      <groupId>org.hamcrest</groupId>
      <artifactId>hamcrest-all</artifactId>
      <version>1.3</version>
</dependency>

附上jar包下载链接:https://download.csdn.net/download/imaniy/10688368

事后分析一下原理

发现:junit使用了hamcrest框架。junit-4.12.jar没有这个框架hamcrest,需要自己导入。

猜你喜欢

转载自blog.csdn.net/IManiy/article/details/82852810