Test Overview
This test uses JUnit's @CsvSource to run the same test method multiple times with different inline CSV data. It verifies that the sum of two numbers equals the expected result.
This test uses JUnit's @CsvSource to run the same test method multiple times with different inline CSV data. It verifies that the sum of two numbers equals the expected result.
import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.CsvSource; import static org.junit.jupiter.api.Assertions.assertEquals; public class CalculatorTest { @ParameterizedTest @CsvSource({ "1, 2, 3", "4, 5, 9", "10, 20, 30" }) void testAddition(int a, int b, int expectedSum) { int actualSum = a + b; assertEquals(expectedSum, actualSum, "Sum should match expected value"); } }
| Step | Action | System State | Assertion | Result |
|---|---|---|---|---|
| 1 | Test starts with first CSV data set (1, 2, 3) | JUnit test runner initializes test method with parameters a=1, b=2, expectedSum=3 | assertEquals(3, 1 + 2) | PASS |
| 2 | Test runs with second CSV data set (4, 5, 9) | JUnit test runner initializes test method with parameters a=4, b=5, expectedSum=9 | assertEquals(9, 4 + 5) | PASS |
| 3 | Test runs with third CSV data set (10, 20, 30) | JUnit test runner initializes test method with parameters a=10, b=20, expectedSum=30 | assertEquals(30, 10 + 20) | PASS |