Search code examples
javajunitassertthat

The method is(int) is undefined


I imported using the following:

import static org.junit.Assert.*;

But on the following line:

assertThat(0, is(1));

I get The method is(int) is undefined for the type AppTest.

The name of this method is so common in the English language that I can not find where to import this.

So my question is, where can I import is (and not).


Solution

  • You need

    import static org.hamcrest.Matchers.is;
    

    is() and many other great helpers are all hamcrest Matchers. And of course, you need the corresponding dependencies defined somehow. It can get a bit tricky, as hamcrest has some core matchers, and also that matchers class with "all" matchers. But once you figured which one works best for you, you are set, and all fine.