-
Here's a code: package com.example;
import org.assertj.core.api.SoftAssertions;
import org.junit.jupiter.api.Test;
import java.util.List;
public class SoftAssertionsTest {
@Test
void testSoftAssertions() {
List.of(1, 2, 3).forEach(element ->
SoftAssertions.assertSoftly(softAssertions ->
softAssertions.fail("Ka-boom! Index: " + element)));
}
} I expected something along the lines of:
Instead, AssertJ quit after the very first assertion error:
Why? Is there some way to manually trigger soft assertion errors in AssertJ? In case you're wondering why I need that, imagine I have a list that expect to be empty, but if it's not, I want to assert on each element with dynamic fail messages (real case) |
Beta Was this translation helpful? Give feedback.
Answered by
NadChel
Nov 29, 2023
Replies: 1 comment
-
I should've called those inside the lambda. Consider it closed @Test
void testSoftAssertions() {
SoftAssertions.assertSoftly(soft -> {
soft.fail("Ka-boom! Index: 1");
soft.fail("Ka-boom! Index: 2");
soft.fail("Ka-boom! Index: 3");
});
} |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
joel-costigliola
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I should've called those inside the lambda. Consider it closed