首页 > 技术文章 > 使用junit测试遇到报错java.lang.NoClassDefFoundError: org/hamcrest/SelfDescribing

dsy665412 2021-12-10 11:41 原文

image
试着翻译了下,翻译不出来。。。。
然后百度查了下,发现是版本的问题,然后把版本降低了,从 4.13.2 到 4.12 还是不行。
再查了百度一下是要换成 4.10 版本,或者 导入hamcrest-core-1.3.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.

翻译过来就是:
包括Hamcrest类。简单的一体化解决方案,快速上手。从版本4.11开始,Hamcrest不再包含在这个jar中。

所以解决方案就是:
1. junit降低版本 4.10
2. 导入 hamcrest-core-1.3.jar

推荐阅读