Tutorial: create a data-driven test with a Databased Testcase
The following screencast shows you, how to create a Repository, a Testset and a Databased Testcase.
Overview of the next steps
- We will use the real-life iTunes Search API.
- We will configure and edit the input teststep (Step 1 )
- We will create an HTTP Teststep to perform the request (Step 2)
- We will read and store a field result count from the HTTP Teststep response
- We will configure the result teststep (Step 4) to contain all input fields and the output field result count
- We will run the databased testcase and review the resulting data (Step 4)
The documentation of this API is provided here on iTunes Search API Documentation Archive
Please don't understand these screenshots as any kind of endorsement from Apple® for this software.
You may use the following request in an application that wants to retrieve a list of apps. We will use one sample request from the iTuneSearchAPI documentation, and include a limit of five results: To search for applications titled “Yelp” and return only the results from th e United States iTunes Store, use the following URL:
https://itunes.apple.com/search?term=yelp&country=us&entity=software&limit=5
When you use the same request with the same parameters, you may more easily follow the instructions and assertion results used in this tutorial. So even if your favorite app isn't the one mentioned above it's worth using it for this tutorial.
We want to demonstrate the Databased Testcase by providing variations of:
- Limit 1, 2, 3 (As the intention of the Search API is not to help out with our tutorial, we want to limit the search results)
- Country (US, Canada)
- Software (Yelp, Apple)
These variations demonstrate how the Databased Testcase works.
Step 1: Enter the Input teststep data with a manual list
We will create a table with the following columns, according to the variations for the URL that we want to demonstrate:
- Limit
- Country
- Software
The Data Loop Input Teststep we automatically create Variables for us that we can use in the parameter list of our URL
We will create the following new table contents:
| Limit | Country | Software |
|---|---|---|
| 1 | US | Apple |
| 2 | CA | Apple |
| 3 | US | Yelp |
After entering the table, select the second row und click the Run Button:
With this configuration in place, you can easily create new rows, which is not required for the tutorial. Select a specific row if you want to test manually a specific row.
Step 2: Edit the URL and run the Search iTunes HTTP Teststep
We create an new HTTP teststep Search iTunes and copy the URL in the URL textfield: https://itunes.apple.com/search?term=yelp&country=us&entity=software&limit=5
We run the teststep and will get a JSON Response as in this sceenshot:
This works, but it's hard to read AND even harder to maintain. So lets switch the URL edit mode to URL with separate list for route parameters and query parameters
Finally, we will replace the static parameter values with their variable placeholders, keeping the static Software parameter:
- term -> $(Testcase.Software)
- country -> $(Testcase.Country)
- limit -> $(Testcase.Limit)
Step 3: Read results from the HTTP response
We want to compare each input result count from the parameter list with the response result count as we think, that they are not always equal altough they should be. We could an assertion, but this time we want to store each dataset row's result.
We create a simple Datatransfer Teststep and read the resultCount information from the JSON response body.
Step 4: Edit and run the DataLoop Result Teststep
We are almost done. We store: - Limit (input) - Country (input) - Software (input) - result count (output)
We select the DataLoop ResultTeststep as shown below and configure our results and run the teststep to verify the expected output.
Step 4 Run the Databased Testcase and the DataLoopResultTeststep
We run the DatabasedTestcase itself in the Testcase List View and see how this testcase iterates of the rows of the DataLoopInputTeststep.
We hope this tutorial was helpful and you enjoy using APIJockey TEST.