Basic Concepts of Data-Driven Testing

Applies to ReadyAPI 3.56, last modified on November 21, 2024

About Data-Driven Testing

Automated tests send requests to the tested web service and cover a certain area of this service. Rather often, they use only one set of parameters, that is, check one set of data. It is quite possible that this data does not cause errors in web service functioning, but other data may cause them. To get better coverage, you can run tests with different data. This will help you ensure that your API works as expected for various input values. This is what data-driven testing is about.

You can create several requests or test cases with different data. However, a better approach is to separate data from test steps. That is, instead of using hard-coded values, a data-driven test can read test data from some storage, like a CSV file or database, and use this data to parameterize requests it sends. This separation makes your test logically simpler. Also, it is easier to edit and maintain such tests in comparison with a test that contains several sets of hard-coded values.

It is considered to be a good practice to store both input data and verifying values in a data storage. This approach lets you easily specify verification data for each portion of test data.

Supported Data Storages

In ReadyAPI, you can use various data sources:

  • External files: comma-separated value files (.csv), Excel sheets, and so on.
  • Databases: MySQL, Oracle, Microsoft SQL Server, and others.
  • Internal data sources (you can create a table data source and fill it with data manually, or you can use a built-in data generator).

For complete information, see Data Source Types.

How to Set up a Data Source Loop

The essence of data-driven testing is running the same steps repeatedly with different data. For that, you need to add a data source loop to your test case.

There are several ways of setting up a data source loop:

  • Create a Data Source test step and click Yes in the Generate properties dialog. This will automatically create and configure a data source loop and let you choose multiple request test steps to include in it.

    Setting up a data source loop in ReadyAPI: Automatic setup

    Click the image to enlarge it.

  • Open a request test step and click Generate Values. This will automatically create and configure a data source loop that includes only this test step.

    Setting up a data source loop in ReadyAPI: Generate values

    Click the image to enlarge it.

  • Create a Data Source Loop test step and configure it manually.

Configuring Data Source Loop Test Step

To configure the data source loop:

  • Double-click the Data Source Loop test step.

  • Select the data source to be used in the loop.

  • Select the target test step. This will be the step from which the loop will start.

    Setting up a data source loop in ReadyAPI: Select the data source and target test step

    Click the image to enlarge it.

  • Close the dialog and put all the steps that you want to iterate through after the target test step and before the loop test step. Make sure that the data source test step is placed before the beginning of the loop.

    Setting up a data source loop in ReadyAPI: Position test steps

For details on the Data Source Loop test step, see Data Source Loop Test Step.

How to Refer Data in Tests

  1. You add the Data Source test step to your test case and connect it to a data source of the supported type (see above).

  2. You then select the data source columns to be available in tests. In ReadyAPI terms, these columns are called properties.

  3. To refer to a property, you use special expressions called property expansions, for example:

    Web service testing with ReadyAPI: Property expansions

    The test engine will “expand” this expression during the test run. For complete information on them and supported syntax, see Property Expansion.

    You can type these expressions, or use the Get Data command to invoke a dialog, where you can choose the needed property visually (see below). You can find this command in the context menu. Some edit boxes and grid cells also offer the ellipsis button:

    Web service testing with ReadyAPI: The Get Data command
    Web service testing with ReadyAPI: Calling the Get Data dialog (ellipsis button)

    Here is a sample view of the dialog:

    Web service testing with ReadyAPI: The Get Data dialog

    Click the image to enlarge it.

    Property expansions are universal. You can use them not only to retrieve database data, but also to extract values from XML and JSON responses and pass them to other test steps.

For detailed step-by-step explanation, see Tutorials below.

For an example of using property expansion in a JSON body, see Examples of Using Properties.

Where Can I Insert Data?

Almost anywhere:

  • Request parameters, headers, and bodies (to simulate requests with different data)
  • Assertions (to verify received responses)
  • Virtual service responses
  • Test step properties
  • And so on

Tutorials

Follow these links to learn how you can use various data sources for data-driven testing of your APIs:

See Also

Transferring Property Values
Property Expansion
Data Sources and Data-Driven Tests

Watch the video
 
Highlight search results