Test Overview
This test checks if a simple addition method works correctly. It uses a clear and descriptive test method name to show what is being tested and what the expected result is.
This test checks if a simple addition method works correctly. It uses a clear and descriptive test method name to show what is being tested and what the expected result is.
import static org.junit.jupiter.api.Assertions.assertEquals; import org.junit.jupiter.api.Test; public class CalculatorTest { @Test void addition_of_two_positive_numbers_should_return_correct_sum() { Calculator calc = new Calculator(); int result = calc.add(2, 3); assertEquals(5, result, "2 + 3 should equal 5"); } } class Calculator { int add(int a, int b) { return a + b; } }
| Step | Action | System State | Assertion | Result |
|---|---|---|---|---|
| 1 | Test runner starts and looks for test methods | JUnit identifies method named 'addition_of_two_positive_numbers_should_return_correct_sum' with @Test annotation | - | PASS |
| 2 | JUnit creates Calculator instance and calls add(2, 3) | Calculator object ready, add method invoked with inputs 2 and 3 | - | PASS |
| 3 | JUnit asserts that result equals 5 | Result from add method is 5 | assertEquals(5, result) | PASS |
| 4 | Test completes successfully | No exceptions thrown, test method finished | - | PASS |