prasan
prasan

Reputation: 191

Unable to import org.junit.Assert.AssertThat;

I am unable to import org.junit.Assert.AssertThat in my program. I am using Ganymede and jUnit 4.8.1.

Upvotes: 19

Views: 48449

Answers (4)

Stimpson Cat
Stimpson Cat

Reputation: 1508

Try this:

import static org.assertj.core.api.Assertions.assertThat;

Upvotes: 1

Sean Patrick Floyd
Sean Patrick Floyd

Reputation: 299098

Static Imports

It's org.junit.Assert.assertThat(T, Matcher<T>) and you can import it as a static import:

import static org.junit.Assert.assertThat

now in your client code you can do assertThat(something, ismatched())

Reference: Java Tutorial > The Static Import Statement


Regular Imports

To do it the old-school way, if you import the Assert class like this

import org.junit.Assert

you can call it using Assert.assertThat(something, isMatched())

(The isMatched() method is something that you'd have to implement)


assertThat()

assertThat() was first described in this blog post and has been part of JUnit ever since version 4.4, so make sure you have JUnit version 4.4 or newer on the classpath. Also, make sure that your compiler compliance level is 1.5 or higher:

Set Eclipse compiler compliance level

Upvotes: 21

DwB
DwB

Reputation: 38320

Assuming that by "i am using ganymede" you are stating that you are using the "ganymede version of eclipse", do the following:

  1. Open the project properties.
  2. Click on "Java Build Path".
  3. Select the Libraries tab.
  4. Click the "Add Library" button.
  5. Choose junit.

You should now be able to import junit classes into your project.

Upvotes: 2

Joachim Sauer
Joachim Sauer

Reputation: 308149

The method is called assertThat (lower a, capital T). And if you import it like that you need to use a static import:

import static org.junit.Assert.assertThat;

But since you don't tell us the error message I can't really tell if that will work for you.

Upvotes: 3

Related Questions