Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content
This repository was archived by the owner on Oct 4, 2020. It is now read-only.

Commit 7c28681

Browse files
author
nipa
committed
Show group assertion error without failing the test
1 parent 00e56cc commit 7c28681

File tree

1 file changed

+15
-5
lines changed

1 file changed

+15
-5
lines changed

src/test/java/org/codefx/lab/junitlambda/_1_Assertions.java

+15-5
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import java.io.IOException;
66
import java.util.function.BooleanSupplier;
77

8+
import static org.codefx.lab.junitlambda.Console.print;
89
import static org.junit.gen5.api.Assertions.assertAll;
910
import static org.junit.gen5.api.Assertions.assertEquals;
1011
import static org.junit.gen5.api.Assertions.assertFalse;
@@ -18,6 +19,8 @@
1819

1920
public class _1_Assertions {
2021

22+
private static final boolean CATCH_GROUP_ASSERTION_FAILURE_MESSAGE = true;
23+
2124
@Test
2225
public void boringAssertions() {
2326
String mango = "Mango";
@@ -61,11 +64,18 @@ public void exceptionAssertions() {
6164

6265
@Test
6366
public void groupedAssertions() {
64-
assertAll("Multiplication",
65-
() -> assertEquals(15, 3 * 5, "3 x 5 = 15"),
66-
// this fails on purpose to see what the message looks like
67-
() -> assertEquals(15, 5 + 3, "5 x 3 = 15")
68-
);
67+
try {
68+
assertAll("Multiplication",
69+
() -> assertEquals(15, 3 * 5, "3 x 5 = 15"),
70+
// this fails on purpose to see what the message looks like
71+
() -> assertEquals(15, 5 + 3, "5 x 3 = 15")
72+
);
73+
} catch (AssertionError e) {
74+
if (CATCH_GROUP_ASSERTION_FAILURE_MESSAGE)
75+
print("Assertion failed - message starts in next line:\n" + e.getMessage());
76+
else
77+
throw e;
78+
}
6979
}
7080

7181
}

0 commit comments

Comments
 (0)