JUnit-4.12使用报java.lang.NoClassDefFoundError: org/hamcrest/SelfDescribing错误

今天尝试使用JUnit,下载了最新的JUnit版本,是4.12,结果尝试使用发现总是报Java.lang.NoClassDefFoundError: org/hamcrest/SelfDescribing这样的错误,上网查了一下,一般的解决方案是,换一个低一点的版本就好了。还有人说,是缺少hamcrest的包。去官网又看了一下,结果发现这样一段话:

  • junit.jar: Includes the Hamcrest classes. The simple all-in-one solution to get started quickly.Starting with version 4.11, Hamcrest is no longer included in this jar.
  • junit-dep.jar: Only includes the JUnit classes but not Hamcrest. Lets you use a different Hamcrest version.

注意黑色加下划线的部分。说明4.12中没有hamcrest包了。


解决方法是:


网上给出的方案,自己的行不通】导入包的方案:junit.jar + hamcrest-core.jar + hamcrest-library.jar

最终】是:junit-dep.ajr+hancrest-all.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>


这两种导入方法虽然尽量避免了导入重复的包,但使用时还是遇到了冲突。查看包中各类和文档后发现有些类(例如:断言is())同时出现在了org.hamcrest.Mathchers和org.hamcrest.core中,则在用到时候引入的时候需要注意。

  • 1
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值