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.
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.
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.
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.
For details on the Data Source Loop test step, see Data Source Loop Test Step.
How to Refer Data in Tests
You add the Data Source test step to your test case and connect it to a data source of the supported type (see above).
You then select the data source columns to be available in tests. In ReadyAPI terms, these columns are called properties.
To refer to a property, you use special expressions called property expansions, for example:
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:
Here is a sample view of the dialog:
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?
- 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
Follow these links to learn how you can use various data sources for data-driven testing of your APIs:
Transferring Property Values
Data Sources and Data-Driven Tests