Test Overview
This test checks a simple method that returns the maximum of two numbers. It verifies both line coverage and branch coverage by testing different input cases to cover all decision paths.
This test checks a simple method that returns the maximum of two numbers. It verifies both line coverage and branch coverage by testing different input cases to cover all decision paths.
import static org.junit.jupiter.api.Assertions.assertEquals; import org.junit.jupiter.api.Test; class MaxUtil { public static int max(int a, int b) { if (a > b) { return a; } else { return b; } } } class MaxUtilTest { @Test public void testMaxFirstGreater() { assertEquals(5, MaxUtil.max(5, 3)); } @Test public void testMaxSecondGreater() { assertEquals(7, MaxUtil.max(4, 7)); } @Test public void testMaxEqual() { assertEquals(6, MaxUtil.max(6, 6)); } }
| Step | Action | System State | Assertion | Result |
|---|---|---|---|---|
| 1 | Test runner starts and loads MaxUtilTest class | JUnit test environment initialized | - | PASS |
| 2 | Runs testMaxFirstGreater: calls MaxUtil.max(5, 3) | Inside max method with a=5, b=3 | Check if a > b (5 > 3) is true | PASS |
| 3 | Returns 5 from max method | max method returns 5 | Assert returned value equals 5 | PASS |
| 4 | Runs testMaxSecondGreater: calls MaxUtil.max(4, 7) | Inside max method with a=4, b=7 | Check if a > b (4 > 7) is false | PASS |
| 5 | Returns 7 from max method | max method returns 7 | Assert returned value equals 7 | PASS |
| 6 | Runs testMaxEqual: calls MaxUtil.max(6, 6) | Inside max method with a=6, b=6 | Check if a > b (6 > 6) is false | PASS |
| 7 | Returns 6 from max method | max method returns 6 | Assert returned value equals 6 | PASS |
| 8 | Test runner finishes all tests | All tests executed | All assertions passed | PASS |