-
Notifications
You must be signed in to change notification settings - Fork 378
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Not sure why assertThat() doesn't work in this case #356
Comments
I tried the following as well, which compiles, but still doesn't pass the test as I thought it would: assertThat(list, allOf(contains(containsString("a")), not(contains(containsString("b"))))); In the end I used JUnit5's ParameterizedTest like as seen below, to accomplish what I wanted: Two assertions against each element in the list. @ParameterizedTest
@ValueSource(strings = { "a", "ca", "ad", "ea", "af" })
void test3(String val) {
assertThat(val, containsString("a"));
assertThat(val, not(containsString("b")));
} Not sure if there is a better way to do it with Hamcrest though. 🤷 |
assertThat(list, allOf(hasItem("a"), not(hasItem("b")))); |
The second and third
assertThat
statements don't compile, but I'm not sure why. I'm using Hamcrest 2.2 with JDK 17 and JUnit5.This is the error I get.
Error on the second
assertThat()
:Error on the third
assertThat()
:The text was updated successfully, but these errors were encountered: