Parameterized Test with @CsvFileSource

This lesson demonstrates the use of @CsvFileSource to pass different arguments to @ParameterizedTest.

We'll cover the following

@CsvFileSource

@CsvFileSource allows you to use CSV files from the classpath. This csv file gets picked up from the classpath at the time of running test case and each line from a CSV file results in one invocation of the parameterized test. We can also provide a number of lines to skip from top to take comma-separated values.

Let’s look at a demo.

Step 1 - Let’s assume that we have to write a parameterized test that takes values from @CsvFileSource.

Step 2 - We create a csv file by name, capitals.csv. It has comma-separated values of countries and their capitals.

Step 3 - We will keep this csv file on the classpath.

Get hands-on with 1400+ tech skills courses.