What is Data-Driven Testing?

Data-driven testing is the practice of running automated tests that simulate user actions over an application with different input data.

This way, you provide larger coverage and ensure the application works properly with different data rather than with one set of values. To accomplish this, external data is loaded into your functional tests and used to extend your automated test cases.

How Does Data-Driven Testing Work?

As the name suggests, you’ll need a set of input data for your automated tests. This data is often stored in an external file such as an Excel sheet, CSV file, database, or table variable. This allows you to modify the data easily. To add more data, simply adjust the values in a text editor or in Excel.

This also helps keep your input data separate from your test scripts. However, if you have hard-coded values, you’ll need to modify both the data and the code itself.

Microsoft Excel

In your file, each row has values that will be assigned or checked. You could use one row of values or multiple rows of values for a single automated test. If you choose to use multiple rows, you’ll need to add a field specifying which values are input, and which are verifying.

After inputting your data, it will be fed line-by-line into the functional test until there are no more. In theory, your automated test projects can be infinitely extended. New automated test cases that are added to the external data simply extend the loop for each new line of data.

When the storage contains both input and verifying data, a data-driven test includes the following operations performed in a loop:

  • Retrieving input data from storage
  • Entering data in an application form
  • Verifying the results
  • Continuing with the next set of input data

Data-Driven Testing Example Scenario

Data-driven testing is particularly useful for inputs on a customer order form.

For your order form, you would record a single automated test, entering values into the various fields. After you record the test, it will only contain values that you entered during the recording. This means you can be certain the data you specify won’t cause errors in the application, but other data may cause unexpected issues.

To ensure the order form works as expected, you would alter the test to accept variables and enter those variables into the data fields. This allows you to run the test as many times as needed, inputting a new set of data each time.

Data-Driven Tests vs Keyword-Driven Tests

Data-driven testing and keyword-driven testing may sound similar, but they’re different testing methodologies.

A keyword-driven test is a great way for non-technical users to create and execute automated tests. Each test contains a keyword defining the action to be performed by a test. Each keyword corresponds to an individual testing action such as a mouse click, selection of a menu item, or opening a window.

To perform any testing actions, testers can drag and drop the keyword that corresponds to the desired operation. Or they can record their actions and the keyword-driven test is built for them.

While these two types of testing may be different, you can easily practice both using an automated testing tool.

How to Practice Data-Driven Testing

SmartBear offers TestComplete, which enables testers of any skill level to create automated tests for web, desktop, mobile, and packaged applications. Using this automated testing tool, you can create simple yet robust data-driven tests.

To produce data automatically, TestComplete has a data generator feature. After you specify the desired parameters, TestComplete will create test data of various types and store it in a table variable or an Excel file. This approach decreases the time spent on preparing data for data-driven tests. But if you already have a set of values you want to use, you can also populate the storages manually.

To create data-driven tests with TestComplete, there are a few methods you can use:

DB Table variables: Each DB table stores links to database tables and queries. It also provides serial access to their records. The DB table variables are commonly used by the data-driven loop keyword-driven test operation. It allows you to iterate through the table rows. When you add this operation to the test, you specify the DB table variable that will access the specified database table. You must also specify the records that will be processed by the operation.

They also provide you with forward and read-only access to the desired database records. These variables support retrieving data from the following storages:

  • Database tables or queries
  • Excel files
  • CSV (comma-separated values) files

Table variables: These variables let you store test data in two-dimensional arrays (tables) and then use it in your data-driven tests. The array elements have the variant type and can store any value. This could be a number, a string, a date and so on. You can also specify the names of array columns and then address the values using these names.

DDT program object: Via this object you can create scripts for data-driven tests. It can be very useful if you want to create a custom test or go through the database records in a defined direction. It’s also used for backward compatibility.

You can use each of these approaches to iterate through records of the desired table, retrieve them, and use them in your automated tests. To see a data-driven testing tutorial in TestComplete, click here.

Try Data-Driven Testing Today

Data-driven testing is a powerful approach that can enhance the efficiency and effectiveness of your testing efforts. By embracing this methodology, you can deliver more reliable software, ensuring a better user experience and greater satisfaction for both your team and your customers.

Want to try data-driven testing?