为什么 JUnit 4.11 在 Ant 构建文件中不工作,但 JUnit 4.8.2 工作正常?

Why JUnit 4.11 is not working in Ant build file, but JUnit 4.8.2 is working fine?

我在 Java 项目中使用 IntelliJ。由于我是 Java 的新手,我在我的项目中尝试将 Ant 作为构建工具。

当我在我的 Ant 构建文件中使用 Junit 4.11 时,出现以下错误:

[javac] /Users/rajatg/fizz-buzz/src/test/FizzBuzzTest.java:4: error: package org.hamcrest.core does not exist
[javac] import static org.hamcrest.core.Is.is;
[javac]                                ^
[javac] /Users/rajatg/fizz-buzz/src/test/FizzBuzzTest.java:4: error: static import only from classes and interfaces
[javac] import static org.hamcrest.core.Is.is;
[javac] ^
[javac] 2 errors

BUILD FAILED

当我使用 Junit 4.8.2 时,所有测试 运行 成功。

谁能告诉我,这是什么问题? 提前致谢。

Junit 4.11 具有 org.hamcrest.core 的编译时依赖性。您应该将 org.hamcrest.core 添加到类路径中。

http://mvnrepository.com/artifact/junit/junit/4.11

Junit 4.8.2 没有编译时依赖。从下面的link可以看出,org.hamcrest.core包已经在junit jar中了

http://mvnrepository.com/artifact/junit/junit/4.8.2