Test Overview
This test checks if all methods in a simple Calculator class are called during testing. It verifies test completeness by measuring code coverage.
This test checks if all methods in a simple Calculator class are called during testing. It verifies test completeness by measuring code coverage.
import static org.junit.jupiter.api.Assertions.*; import org.junit.jupiter.api.Test; class Calculator { int add(int a, int b) { return a + b; } int subtract(int a, int b) { return a - b; } } public class CalculatorTest { @Test void testAdd() { Calculator calc = new Calculator(); int result = calc.add(5, 3); assertEquals(8, result); } }
| Step | Action | System State | Assertion | Result |
|---|---|---|---|---|
| 1 | Test starts | JUnit test runner initializes | - | PASS |
| 2 | CalculatorTest.testAdd() method is called | Calculator instance created | - | PASS |
| 3 | Calculator.add(5, 3) method is called | Inside add method, parameters a=5, b=3 | - | PASS |
| 4 | add method returns 8 | Return value 8 passed back to testAdd | - | PASS |
| 5 | testAdd asserts result equals 8 | Assertion compares expected 8 with actual 8 | assertEquals(8, result) | PASS |
| 6 | Test ends | Test runner completes testAdd | - | PASS |
| 7 | Coverage report generated | Report shows add method covered, subtract method not covered | Coverage measures which methods ran during tests | PASS |