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

标签 java eclipse junit import

我无法在我的程序中导入 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 或更高:

Set Eclipse compiler compliance level

关于java - 无法导入 org.junit.Assert.AssertThat;,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4933402/

相关文章:

java - 使用batcher.drawSprite绘制游戏中的所有图像是否正确?

java - 通过减少列表上的代码/操作量来优化方法

java - 如何查找附加到数组的特定索引的值

java - WebApplicationContext 未在 Servlet 上下文重新加载时关闭

eclipse - 安卓 : permissions missing name and tags

c - 我的C语言程序可以编译,但是不产生任何输出

java - 在 Eclipse 中方便快捷地从多个项目运行 Junit-Tests

java - Android Studio 2.1 : error: package org. junit 不存在

java - 我们如何为将输出写入文件的方法编写 JUnit?

java - 使用 IgniteFuture 进行单元测试