Test Overview
This test uses the @Tag annotation to categorize tests. It verifies that a simple addition method returns the correct result.
This test uses the @Tag annotation to categorize tests. It verifies that a simple addition method returns the correct result.
import org.junit.jupiter.api.Tag; import org.junit.jupiter.api.Test; import static org.junit.jupiter.api.Assertions.assertEquals; public class CalculatorTest { @Tag("math") @Test void testAddition() { int result = add(2, 3); assertEquals(5, result, "2 + 3 should equal 5"); } int add(int a, int b) { return a + b; } }
| Step | Action | System State | Assertion | Result |
|---|---|---|---|---|
| 1 | Test runner starts and identifies tests with @Tag("math") | JUnit test environment ready, CalculatorTest loaded | - | PASS |
| 2 | JUnit runs testAddition() method | Inside testAddition method, variables initialized | - | PASS |
| 3 | Calls add(2, 3) method | add method executes and returns 5 | - | PASS |
| 4 | Assert that result equals 5 | Result is 5, expected is 5 | assertEquals(5, result) | PASS |
| 5 | Test completes successfully | Test marked as passed in report | - | PASS |