Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

I am using IntelliJ for the Java Projects. As I am new to Java, I tried Ant as a build tool in my project.

When I am using Junit 4.11 in my Ant build file, I am getting 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, then all the tests ran successfully.

Can anyone tell me please, what is this issue? Thanks in advance.

like image 426
Rajat Gupta Avatar asked Jul 20 '15 03:07

Rajat Gupta


People also ask

How do you skip the test in Ant build?

If your project's build file is constructed like that, then it's a matter of running ANT with the compile target and that will skip the tests. If it isn't built like that then there is no other way than to change the build file and separate the unit tests into it's own target that is not the default.


1 Answers

Junit 4.11 has the compile time dependency of org.hamcrest.core. You should add the org.hamcrest.core to your classpath.

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

Junit 4.8.2 doesn't have the 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

like image 183
Reins Avatar answered Oct 02 '22 01:10

Reins