加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > Java > 正文

java – 无法导入org.junit.Assert.AssertThat;

发布时间:2020-12-14 05:46:15 所属栏目:Java 来源:网络整理
导读:我无法在我的程序中导入org.junit.Assert.AssertThat.我使用Ganymede和jUnit 4.8.1. 解决方法 静态导入 它是 org.junit.Assert.assertThat(T,MatcherT) ,您可以将其导入为静态导入: import static org.junit.Assert.assertThat 现在在你的客户端代码中你可
我无法在我的程序中导入org.junit.Assert.AssertThat.我使用Ganymede和jUnit 4.8.1.

解决方法

静态导入

它是org.junit.Assert.assertThat(T,Matcher<T>),您可以将其导入为静态导入:

import static org.junit.Assert.assertThat

现在在你的客户端代码中你可以做assertThat(something,ismatched())

参考:Java Tutorial > The Static Import Statement

定期进口

要做这个老派的方法,如果你这样导入Assert类

import org.junit.Assert

你可以使用Assert.assertThat(something,isMatched())来调用它

(isMatched()方法是你必须实现的)

assertThat()

assertThat()首先描述为in this blog post,并已成为JUnit ever since version 4.4的一部分,因此请确保您在类路径上具有JUnit版本4.4或更高版本.此外,请确保您的编译器合规级别为1.5或更高版本:

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读