0

Using JUnit5 assertAll, I call a method to perform assertions but noticed that when the assertion should fail, the test actually passes. It seems calling a method like the below is being ignored.

assertAll(
    () -> jsonAssertions(actual, expectedUrl)
);

private Executable[] jsonAssertions(String actual, String expectedUrl) {
    return new Executable[] {
        () -> ProductAssert.assertThat(actual).urlEquals(expectedUrl)
    };
}

(ProductAssert is a custom assertJ assertion class).


This works fine though

assertAll(
    () -> ProductAssert.assertThat(actual).urlEquals(expectedUrl)
);
Ilyas Patel
  • 400
  • 2
  • 11
  • 27
  • Please [edit] your question to include the source code you have as a [mcve], which can be compiled and tested by others. – Progman Jul 18 '20 at 16:46

1 Answers1

0

JUnit 5 assertAll takes a list of Executable instances.

The way you're doing it now, you're not actually passing the Executable list to assertAll. Instead of passing an anonymous method to assertAll, pass the results of jsonAssertions directly:

@Test
private void test() {
    assertAll(jsonAssertions(actual, expected));
}

private Executable[] jsonAssertions(String actual, String expected) {
    return new Executable[] {
        () -> assertThat(actual).isNotNull(),
        () -> assertThat(expected).isNotNull(),
        () -> assertThat(actual).isEqualTo(expected)
    };
}
blacktide
  • 10,654
  • 8
  • 33
  • 53