我无法在我的程序中导入 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 或更高:
关于java - 无法导入 org.junit.Assert.AssertThat;,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4933402/