Test Overview
This test runs a simple JUnit test case and generates a coverage report to verify which parts of the code were executed during the test.
This test runs a simple JUnit test case and generates a coverage report to verify which parts of the code were executed during the test.
import static org.junit.jupiter.api.Assertions.assertEquals; import org.junit.jupiter.api.Test; class Calculator { public int add(int a, int b) { return a + b; } public int subtract(int a, int b) { return a - b; } } class CalculatorTest { @Test public void testAdd() { Calculator calc = new Calculator(); assertEquals(5, calc.add(2, 3)); } }
| Step | Action | System State | Assertion | Result |
|---|---|---|---|---|
| 1 | Test runner starts and loads CalculatorTest class | JUnit test environment initialized | - | PASS |
| 2 | JUnit executes testAdd() method | Calculator instance created, add method called with (2,3) | assertEquals(5, calc.add(2, 3)) verifies result is 5 | PASS |
| 3 | Test completes successfully | Test method finished without exceptions | - | PASS |
| 4 | Coverage tool analyzes which methods were executed | Coverage data collected for add() method, subtract() method not executed | Coverage report shows add() method covered, subtract() method not covered | PASS |
| 5 | Coverage report generated and saved | Report file available with coverage summary | Report confirms 50% method coverage for Calculator class | PASS |