I have a Junit(5) test case that's looking for an exception when a variable is out of bounds, and I raise an IllegalArgumentException for it.
@Test
void testOutOfBoundsException() {
Foo f = new Foo();
IllegalArgumentException e = assertThrows(
IllegalArgumentException.class,
() -> {
f.checkVal(10);
}
);
assertThat(e, hasMessageThat(containsString("You must enter a number between 0 and")));
}
I get the error
The method containsString(String) is undefined for the type FooTest
I've tried a number of different import statements for JUnit and hamcrest, but I simply can't seem to get this to work.
You can simply use like below instead :
you might need assertj-core :