Chapter 7. Data-Driven Testing

In this chapter, we will cover:

  • Creating a data-driven test using JUnit
  • Creating a data-driven test using TestNG
  • Reading test data from a CSV file using JUnit
  • Reading test data from an Excel file using JUnit and Apache POI
  • Creating a data-driven test in NUnit
  • Creating a data-driven test in MSTEST
  • Creating a data-driven test in Ruby using Roo
  • Creating a data-driven test in Python using DDT

Introduction

The data-driven testing approach is a widely used methodology in software test automation. We can use the same test script to check different test conditions by passing set of data to the test script.

We will use the BMI calculator application as an example to understand the data-driven testing approach.

When testing whether the BMI calculator application indicates BMI categories correctly, instead of having a separate test script for each category, we can have one script that will enter the height and weight by referring to a set of values and checking the expected values.

We can use the following combinations of test conditions to test the BMI calculator application:

Height (centimeters)

Weight (kilograms)

BMI

Category

160

45

17.6

Underweight

168

70

24.8

Normal

181

89

27.2

Overweight

178

100

31.6

Obesity

In the simplest form, the tester supplies inputs from a row in the table and expected outputs, which occur in the same row.

Data-driven approach – workflow

In the data-driven approach, we can maintain the test data in form tables in a variety of formats, such as CSV files, Excel spreadsheets, and databases.

We implement test scripts after reading input and output values from data files row by row, then passing the values to the main test code. Then, the test code navigates through the application, executing the steps needed for the test case using the variables loaded with data values.

Data-driven tests are great for applications involving calculations for testing ranges of values, boundary values, and corner cases.

Benefits of data-driven testing

The benefits of data-driven testing are as follows:

  • With data-driven tests, we can get greater test coverage while minimizing the amount of test code we need to write and maintain
  • Data-driven testing makes creating and running a lot of test conditions very easy
  • Test data can be designed and created before the application is ready for testing
  • Data tables can also be used in manual testing

Selenium WebDriver, being a pure browser automation API, does not provide built-in features to support data-driven testing. However, we can add support for data-driven testing using various options in Selenium WebDriver. In this chapter, we will create some basic data-driven tests in JUnit and TestNG. Later, we will build some advanced data-driven tests using different data sources in JUnit, and a data-driven test in Ruby using Roo and Python.

We will also create data driven tests for .NET bindings using NUnit and MSTest.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.190.160.221