Test Overview
This test checks if the calculator adds two numbers correctly. It uses a single assertion to verify the sum result.
This test checks if the calculator adds two numbers correctly. It uses a single assertion to verify the sum result.
import static org.junit.jupiter.api.Assertions.assertEquals; import org.junit.jupiter.api.Test; public class CalculatorTest { @Test public void testAddition() { Calculator calc = new Calculator(); int result = calc.add(2, 3); assertEquals(5, result, "2 + 3 should equal 5"); } } class Calculator { public int add(int a, int b) { return a + b; } }
| Step | Action | System State | Assertion | Result |
|---|---|---|---|---|
| 1 | Test starts | JUnit test runner initialized | - | PASS |
| 2 | Calculator object created | Calculator instance ready | - | PASS |
| 3 | add method called with 2 and 3 | Method returns 5 | - | PASS |
| 4 | assertEquals checks if result equals 5 | Result is 5 | Verify 5 == 5 | PASS |
| 5 | Test ends | Test passed successfully | - | PASS |