Test Overview
This test runs a simple JUnit test case and verifies that the test result is published correctly as a pass or fail in the test report.
This test runs a simple JUnit test case and verifies that the test result is published correctly as a pass or fail in the test report.
import org.junit.jupiter.api.Test; import static org.junit.jupiter.api.Assertions.assertEquals; public class CalculatorTest { @Test public void testAddition() { int result = 2 + 3; assertEquals(5, result, "2 + 3 should equal 5"); } }
| Step | Action | System State | Assertion | Result |
|---|---|---|---|---|
| 1 | Test runner starts and loads CalculatorTest class | JUnit test environment initialized, test class loaded | — | PASS |
| 2 | JUnit invokes testAddition() method | Inside testAddition method, variables initialized | — | PASS |
| 3 | Calculate result = 2 + 3 | result variable holds value 5 | — | PASS |
| 4 | Assert that result equals 5 using assertEquals | Assertion compares expected 5 with actual 5 | assertEquals(5, result) passes | PASS |
| 5 | JUnit marks testAddition as PASSED | Test report updated with pass status for testAddition | Test result published as PASS in report | PASS |
@Test
void testSum() {
assertEquals(5, 2 + 3);
} @Test
void testEmptyList() {
List<String> list = new ArrayList<>();
assertTrue(list.isEmpty());
}Pass the test and this pattern moves unknown