Test Overview
This test reads multiple sets of input data from an external CSV file using @CsvFileSource. It verifies that the sum of two numbers equals the expected result for each data row.
This test reads multiple sets of input data from an external CSV file using @CsvFileSource. It verifies that the sum of two numbers equals the expected result for each data row.
import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.CsvFileSource; import static org.junit.jupiter.api.Assertions.assertEquals; public class CalculatorTest { @ParameterizedTest @CsvFileSource(resources = "/data/sum-data.csv", numLinesToSkip = 1) void testSum(int a, int b, int expectedSum) { int actualSum = a + b; assertEquals(expectedSum, actualSum, () -> String.format("Sum of %d and %d should be %d", a, b, expectedSum)); } }
| Step | Action | System State | Assertion | Result |
|---|---|---|---|---|
| 1 | Test runner starts and loads the test class CalculatorTest | JUnit test environment initialized | - | PASS |
| 2 | Reads the CSV file '/data/sum-data.csv' skipping the header line | CSV file content loaded: rows of integers for a, b, expectedSum | - | PASS |
| 3 | Executes testSum with first data row (a=1, b=2, expectedSum=3) | Test method invoked with parameters (1, 2, 3) | Check if 1 + 2 equals 3 | PASS |
| 4 | Executes testSum with second data row (a=5, b=7, expectedSum=12) | Test method invoked with parameters (5, 7, 12) | Check if 5 + 7 equals 12 | PASS |
| 5 | Executes testSum with third data row (a=10, b=15, expectedSum=25) | Test method invoked with parameters (10, 15, 25) | Check if 10 + 15 equals 25 | PASS |
| 6 | All parameterized test cases complete | Test report generated showing all tests passed | - | PASS |