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:
Create a
test
class with nameDBTestData
. Make it a parameterized class by adding the@RunWith
attribute.import org.openqa.selenium.WebDriver; import org.openqa.selenium.firefox.FirefoxDriver; import org.openqa.selenium.WebElement; import org.openqa.selenium...