Test Overview
This test uses JUnit to run a parameterized test with custom display names for each parameter set. It verifies that the sum of two numbers matches the expected result.
This test uses JUnit to run a parameterized test with custom display names for each parameter set. It verifies that the sum of two numbers matches the expected result.
import static org.junit.jupiter.api.Assertions.assertEquals; import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.CsvSource; public class CalculatorTest { @ParameterizedTest(name = "Sum of {0} and {1} should be {2}") @CsvSource({ "1, 2, 3", "4, 5, 9", "10, 20, 30" }) void testSumWithCustomDisplayName(int a, int b, int expected) { assertEquals(expected, a + b); } }
| Step | Action | System State | Assertion | Result |
|---|---|---|---|---|
| 1 | Test runner starts and loads CalculatorTest class | JUnit test environment initialized | - | PASS |
| 2 | JUnit identifies parameterized test method testSumWithCustomDisplayName with 3 parameter sets | Test method ready to run with parameters (1,2,3), (4,5,9), (10,20,30) | - | PASS |
| 3 | JUnit runs testSumWithCustomDisplayName with parameters (1, 2, 3) | Test method executing with a=1, b=2, expected=3 | assertEquals(3, 1 + 2) | PASS |
| 4 | JUnit runs testSumWithCustomDisplayName with parameters (4, 5, 9) | Test method executing with a=4, b=5, expected=9 | assertEquals(9, 4 + 5) | PASS |
| 5 | JUnit runs testSumWithCustomDisplayName with parameters (10, 20, 30) | Test method executing with a=10, b=20, expected=30 | assertEquals(30, 10 + 20) | PASS |
| 6 | Test runner completes all parameterized tests and reports results | All parameterized tests passed with custom display names shown in test report | - | PASS |