Reading test data from a database using JUnit and JDBC

In the earlier recipes, we used CSV and Excel spreadsheets to maintain the test data and read this test data in JUnit.

The test data can also be read from a database. This works similar to the previous recipes, however, we will create a helper method using JDBC to read the test data from a Microsoft Access database. This recipe can be used with any database.

Getting ready

  • Set up a new project and add JUnit4 to the project's build path.
  • Create a database with the required data in a test data table. This example uses a Microsoft Access database. The sample file is available with the book's sample code.

How to do it...

Let's implement a parameterized test with CSV by using the following steps:

  1. Create ...

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.