Test Overview
This test checks a simple method that adds two numbers. It verifies the method returns the correct sum.
This test checks a simple method that adds two numbers. It verifies the method returns the correct sum.
import static org.junit.jupiter.api.Assertions.assertEquals; import org.junit.jupiter.api.Test; public class CalculatorTest { @Test public void testAdd() { 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 | CalculatorTest class loaded | CalculatorTest and Calculator classes ready | - | PASS |
| 3 | testAdd method invoked | Calculator object created | - | PASS |
| 4 | add method called with arguments 2 and 3 | Inside add method, inputs received | - | PASS |
| 5 | add method returns 5 | Result 5 returned to testAdd | - | PASS |
| 6 | assertEquals checks if result equals 5 | Comparing expected 5 and actual 5 | assertEquals(5, result) | PASS |
| 7 | Test completes successfully | Test runner records pass | - | PASS |