junit单元测试报错:java.lang.NoClassDefFoundError: org/hamcrest/SelfDescribing

  1. 今天在复习的时候对对一些知识点进行巩固,用到了junit-4.13.jar,手动导入jar包,然后运行然后报错:java.lang.NoClassDefFoundError: org/hamcrest/SelfDescribing。刚开始我以为代码错了,看了看发现不是代码的问题,是导包的问题。然后查询了百度,发现了是版本的问题:
    然后说换个低版本的就可以了,说换成4.10就可以了。测试了一下果然

  2. 查官网:JUnit now uses the latest version of Hamcrest. Thus, you can use all the available matchers and benefit from an improved assertThat which will now print the mismatch description from the matcher when an assertion fails.

  3. 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.11以上版本不在包含hamcrest。
    所以现在有两个办法解决:

    1. junit版本降到4.10
    2. 导入hamcrest-core-1.3.jar

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值