From a013db7dab68a214cc999ee781f3c2d328f37707 Mon Sep 17 00:00:00 2001 From: interrupt-routine <77172657+interrupt-routine@users.noreply.github.com> Date: Thu, 21 Mar 2024 00:19:12 +0100 Subject: [PATCH] Document JUnit 4 message parameter Adding an assertion message to the JUnit 4 demo + documenting the fact that the JUnit optional message parameter comes first in JUnit 4 but last in JUnit 5. --- content/languages/java/junit.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/content/languages/java/junit.md b/content/languages/java/junit.md index f32a2f1b..a1e46461 100644 --- a/content/languages/java/junit.md +++ b/content/languages/java/junit.md @@ -7,6 +7,8 @@ You can use JUnit [4](https://junit.org/junit4/) or [5](https://junit.org/junit5 Note that JUnit assertions use `(expected, actual)` parameter ordering rather than the typical `(actual, expected)`. +Also note that the order of the optional `message` parameter is swapped between JUnit 4 and 5: in JUnit 4 the order is `(message, expected, actual)`; while in JUnit5 it is `(expected, actual, message)`. + ## Basic Setup ### Example solution @@ -28,7 +30,7 @@ import static org.junit.Assert.assertEquals; public class AdderTests { @Test public void testAdd() { - assertEquals(3, Adder.add(1, 2)); + assertEquals("1 + 2 should equal 3", 3, Adder.add(1, 2)); } } ```