2
votes

I have hamcrest-all-1.3 on top of junit-dep jar and still get this exception when I run using ant. However, Eclipse is intelligent enough to resolve this conflict and the test works. I don't have mockito on my classpath, however, do have jmockit and easymock which I believe is not the problem here. Here is the assert:

import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.lessThanOrEqualTo;
/* ...
...
... */


 assertThat(10, lessThanOrEqualTo(20));

Exception is

[junit] org/hamcrest/Matchers

[junit] java.lang.NoClassDefFoundError: org/hamcrest/Matchers

2
Post some code please. Check your manifest to make sure it points to the correct class - Dylan Wheeler
Also please tell more about your environment. Which IDE, how do you run your tests (Eclipse, IntelliJ, Maven, Ant, ...?). - Stefan Winkler
updated the description and posted my coded. I get this error when i run it from ant. Eclipse does resolve this situation though. - Sabarish
updated the description and posted my coded. I get this error when i run it from ant. Eclipse does resolve this situation though. - Sabarish
Could you please use junit-4.12.jar, hamcrest-core-1.3.jar and hamcrest-library-1.3.jar That should solve your problem. - Stefan Birkner

2 Answers

4
votes

You need both hamcrest jars to have this issue resolved as Stefan mentioned. junit-4.12.jar, hamcrest-core-1.3.jar and hamcrest-library-1.3.jar

0
votes

One way to fix such kind of issues: within eclipse, put the cursor on "assertThat" and press F3.

This takes you to the source behind the corresponding class/method. Probably you end up with an empty window, telling you:

Class File Editor

Source not found

to then tell you the name of the JAR file where assertThat is actually to be found; in my case it would be junit-4.11.jar.

So, long story short: check if your build setup does contain a JUnit jar.