• 首页 首页 icon
  • 工具库 工具库 icon
    • IP查询 IP查询 icon
  • 内容库 内容库 icon
    • 快讯库 快讯库 icon
    • 精品库 精品库 icon
    • 问答库 问答库 icon
  • 更多 更多 icon
    • 服务条款 服务条款 icon

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

武飞扬头像
一只小小狗
帮助1

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

JUnit4 大版本 ,出现这个错误,可以退版本到4.10版本解决错误。

查看问题可知

我们报错中出现了hamcrest,我们缺少这个jar。

提供了大量被称为“匹配器”的方法。其中每个匹配器都设计用于执行特定的比较操作。Hamcrest的可扩展性很好,让你能够创建自定义的匹配器。最重要的是,JUnit也包含了Hamcrest的核心,提供了对Hamcrest的原生支持,可以直接使用Hamcrest。

在版本4.11开始 ,JUnit将将Hamcrest移除了,为了更好的搭配更多Hamcrest版本。可以使用一下模式进行匹配

unit-4.1X.jar hamcrest-core-1.X.jar

结论

有2中解决方法

1. 换成junit版本退档 到11以下
2. junit-4.1×.jar hamcrest-core-1.×.jar

例如

		<dependency>
			<groupId>junit</groupId>
			<artifactId>junit</artifactId>
			<version>4.12</version>
			<scope>test</scope>
		</dependency>
		<dependency>
			<groupId>org.hamcrest</groupId>
			<artifactId>hamcrest-junit</artifactId>
			<version>2.0.0.0</version>
			<scope>test</scope>
		</dependency>

这篇好文章是转载于:学新通技术网

  • 版权申明: 本站部分内容来自互联网,仅供学习及演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,请提供相关证据及您的身份证明,我们将在收到邮件后48小时内删除。
  • 本站站名: 学新通技术网
  • 本文地址: /boutique/detail/tanhgcbiif
系列文章
更多 icon
同类精品
更多 icon
继续加载