Adam Sh
Adam Sh

Reputation: 8577

Java/ Using Junit 4 gives compilation error

I got a compilation error in my project on package which belongs to Junit (in org.junit, org.junit.experimental.results, org.junit.internal, org.junit.internal.matchers, org.junit.matchers, org.junit.rules).

all this classes are under junit package in my project, meaning: Security/src/org.junit, Security/src/org.junit.experimental.results, where Security is the name of my project. My classes that I wrote are under other package that I define: Security/src/myPackage/myClass

In all these classes, it gives a complation error in the import lines, for example:

import org.hamcrest.Description cannot be resolved
import org.hamcrest.Matcher cannot be resolved;
import static org.junit.matchers.JUnitMatchers.containsString cannot be resolved;

The checks are going OK (the green/red bar is display, and gives the correct result), but this problem give me an error on all the project.

Upvotes: 0

Views: 3232

Answers (1)

Kai
Kai

Reputation: 39641

Your JUnit version needs Hamcrest. You should include it in your buildpath or use an older JUnit version.

There are different JUnit packages of the release 4.10:

  • junit-4.10.jar: Includes Hamcrest, you should use this.
  • junit-dep-4.10.jar: Does NOT include Hamcrest, use this if you already have a hamcrest jar in your buildpath.

Upvotes: 4

Related Questions