解决Junit单元测试高版本NoClassDefFoundError异常问题

上午在正常使用Junit做测试的时候,抛出了

java.lang.NoClassDefFoundError: org/hamcrest/SelfDescribing

Junit版本是之前maven项目下载的Junit4.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开始,Junit不自带hamcrest包了,所以缺少hamcrest


猜测maven项目没问题的原因应该是:

从中央仓库拿Junit的时候应该会顺带下载hamcrest并依赖


解决方法

方法一:使用4.11以下版本,如:Junit 4.1.0

方法二:再添加一个hamcrest包,如:hamcrest-core-1.3.jar

posted @   konley  阅读(125)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 25岁的心里话
· 闲置电脑爆改个人服务器(超详细) #公网映射 #Vmware虚拟网络编辑器
· 零经验选手,Compose 一天开发一款小游戏!
· 因为Apifox不支持离线,我果断选择了Apipost!
· 通过 API 将Deepseek响应流式内容输出到前端
点击右上角即可分享
微信分享提示