We saw a simple data-driven test TestNG. The test data was hardcoded in the test-script code. This could become difficult to maintain. It is recommended that we store the test data separately from the test scripts. Often, we use data from the production environment for testing. This data can be exported in the CSV format. We can read these CSV files in data-provider methods and pass the data to the test instead of hardcoded object arrays.
In this example, we will use the OpenCSV library to read a CSV file. OpenCSV is a simple Java library for reading CSV files in Java. You can find more details on OpenCSV at http://opencsv.sourceforge.net/.
Let's first create a CSV file, named data.csv, in the src/test/resources/data ...