Java /使用Junit 4会出现编译错误

时间:2012-04-25 14:22:58

标签: java junit

我的程序包属于Junit(在org.junit, org.junit.experimental.results, org.junit.internal, org.junit.internal.matchers, org.junit.matchers, org.junit.rules中)的项目中出现了编译错误。

所有这些类都在我的项目中的junit包下,意思是:Security/src/org.junit, Security/src/org.junit.experimental.results,其中Security是我项目的名称。我编写的类是在我定义的其他包中:Security/src/myPackage/myClass

在所有这些类中,它在导入行中给出了一个编译错误,例如:

import org.hamcrest.Description cannot be resolved
import org.hamcrest.Matcher cannot be resolved;
import static org.junit.matchers.JUnitMatchers.containsString cannot be resolved;

检查正常(显示绿色/红色条,并给出正确的结果),但是这个问题在所有项目上都给出了错误。

1 个答案:

答案 0 :(得分:4)

您的JUnit版本需要Hamcrest。您应该将它包含在构建路径中或使用较旧的JUnit版本。

版本4.10有不同的JUnit包:

  • junit-4.10.jar:包括Hamcrest,你应该使用它。
  • junit-dep-4.10.jar:不包含Hamcrest,如果你的构建路径中已经有一个hamcrest jar,请使用它。