Test Overview
This test checks if the addition method returns the correct sum. It verifies the expected outcome using assertions to ensure the method works as intended.
This test checks if the addition method returns the correct sum. It verifies the expected outcome using assertions to ensure the method works as intended.
import static org.junit.jupiter.api.Assertions.assertEquals; import org.junit.jupiter.api.Test; public class CalculatorTest { public int add(int a, int b) { return a + b; } @Test public void testAdd() { CalculatorTest calculator = new CalculatorTest(); int result = calculator.add(2, 3); assertEquals(5, result, "Addition result should be 5"); } }
| Step | Action | System State | Assertion | Result |
|---|---|---|---|---|
| 1 | Test starts | JUnit test runner initialized | - | PASS |
| 2 | Creates CalculatorTest instance | CalculatorTest object ready | - | PASS |
| 3 | Calls add(2, 3) method | Method executes and returns 5 | - | PASS |
| 4 | Assert that result equals 5 | Result is 5 | assertEquals(5, result) | PASS |
| 5 | Test ends successfully | Test passed with no errors | - | PASS |