我的项目中属于 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;
检查进展顺利(显示绿色/红色条,并给出正确的结果),但是这个问题给我所有项目带来了错误。
最佳答案
您的 JUnit 版本需要 Hamcrest。您应该将其包含在构建路径中或使用旧的 JUnit 版本。
4.10 版本有不同的 JUnit 包:
- junit-4.10.jar:包括 Hamcrest,您应该使用它。
- junit-dep-4.10.jar:不包括 Hamcrest,如果您的构建路径中已经有 hamcrest jar,请使用它。
关于Java/使用 Junit 4 给出编译错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10317701/