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

JUnit4.12使用报java.lang.NoClassDefFoundError: org/hamcrest/SelfDescribing错误解决方法
网上提供的方案
导入包的方案: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,需要自己导入。

相关文章:

  • 2021-07-15
  • 2022-12-23
  • 2022-12-23
  • 2021-08-30
  • 2021-08-01
  • 2021-06-10
  • 2021-11-12
猜你喜欢
  • 2021-12-29
  • 2021-08-05
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案