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

I am using IntelliJ for Java projects. Since I'm new to Java, I tried Ant as a build tool in my project.

When I use Junit 4.11 in the Ant build file, I get the following errors:

[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 

And when I used Junit 4.8.2, all tests ran successfully.

Can someone please tell me what the problem is? Thanks in advance.

+5
source share
1 answer

Junit 4.11 has an org.hamcrest.core compile time dependency. You must add org.hamcrest.core to your classpath.

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

Junit 4.8.2 has no compile time dependency. As you can see from the following link, the org.hamcrest.core package is already in the junit jar.

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

+6
source

All Articles