This article is a follow-up to two previous blog posts:
If you haven't read these articles yet, I highly recommend checking them out before proceeding with this one.
In this article, I will present three advanced examples of API testing and simulation using OSV:
This section outlines the process for testing an API that provides different responses to identical requests.
In this example, an API is called with 3 parameters (surname, name, age), leading to the creation of a record in the backend. The API confirms the successful addition and returns the ID of the new record. If the same request is submitted again, the API responds with a message indicating that the record already exists.
To test this type of process, the API will be scanned twice to capture the responses. The TestSteps will then be assembled as follows:
The process can then be visualized as follows by clicking on the "Sequence Flow Diagram" tab:
It's worth noting that this interaction can also be easily converted into an OSV scenario.
Once deployed, the scenario can be accessed in the OSV Monitor.
This section explains the procedure for testing multiple API requests with varying values. In the example below, the API is called to retrieve the stock price in different currencies. The request includes a single parameter representing a currency (GBP, EUR, or USD). The API responds with a numeric value.
To create a more versatile test, value ranges will be defined for each currency, and the expected results will be summarized in the following TestSheet:
Next, the test script is converted into a template, and the TestSheet is mapped to the TestCase.
Finally, the TestCase can be instantiated to generate the test scripts:
You can also create an OSV service based on the instantiated template if desired.
In this final section, the procedure for configuring OSV to handle specific responses for requests that differ from the predefined ones will be outlined. In the example below, an API simulated via OSV returns the stock price in two currencies (USD and EUR).
The OSV scenarios are structured as follows:
If a request is made with an undefined currency, such as CHF, the system will return:
404 Not Found
No scenario found that matches the incoming message.
For example, if the requirement is that undefined currencies (i.e., any currency other than USD or EUR) should return the value "999," this can be represented as follows:
To achieve this behavior, the following scenario will be created and deployed:
When testing the OSV service, it is observed that while the behavior is correct for all currencies other than USD and EUR, an error occurs for USD and EUR. The error message is:
Found multiple matches with the same weight, aborting this match completely!
Scenario: Stock Price Request EUR; Step: 1; Weight: 0; Rules ->
Value: 'EUR' Path: currency
Scenario: Stock Price Request OTHER CURRENCIES; Step: 1; Weight: 0; Rules ->
Value: '*' Path: currency
This issue arises because both EUR and USD match multiple scenarios with the same weight. Specifically, "EUR" matches the scenario Stock Price Request EUR with the value "EUR" and also matches the Stock Price Request OTHER CURRENCIES with the value "*".
To ensure that the Stock Price Request OTHER CURRENCIES scenario is used as the default response only when other scenarios are not applicable, a Virtualization parameter called WEIGHT will be added.
To implement this, go to the OSV module "Request" and add the WEIGHT parameter as a Module Attribute.
Next, set the Weight value to -1 in your Stock Price Request OTHER CURRENCIES scenario and redeploy it.
Your service is now functioning as desired!
This article presents advanced examples of API testing and simulation with OSV, including testing complete API workflows, handling varying values with TestSheets, and defining generic responses for unknown requests. These insights complete our exploration of API and OSV integration with Tricentis on-prem tools (TTA and ECT).
Follow my profile for updates on future posts, and feel free to ask any questions in the comments below!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
| User | Count |
|---|---|
| 36 | |
| 28 | |
| 27 | |
| 26 | |
| 26 | |
| 26 | |
| 24 | |
| 23 | |
| 22 | |
| 22 |