Reading test data from a CSV file using JUnit

We saw a simple data-driven test using JUnit and TestNG. The test data was hardcoded in 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 CSV format. We can read CSV files using Java IO and utility classes and can pass the data from these files to the test code.

Reading test data from a CSV file using JUnit

In this recipe, we will read data from a CSV file and use this data to execute the test script.

Getting ready

  • Set up a new project and add JUnit4 to the project's build ...

Get Selenium Testing Tools Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.