Mock Service Templates are common collections of Transactions and Parameter selections that you can reuse when you need to test against those Transactions. For example, for a login service, you might create a Template that includes a few Transactions required for negative testing. Then, when you need to test those scenarios, you can quickly provision a Mock Service based on that Template to test with.
Templates override the Transactions that are directly in a Mock Service, and are meant to be a more persistent way to add commonly grouped Transactions to a Mock Service on the fly.
- Create a Mock Service Template
- Create a Mock Service from a Mock Service Template
- Assign a Template to a Mock Service
- Create a Mock Service Template from a Mock Service
Create a Mock Service Template
Follow these steps:
- Log into your BlazeMeter account.
- In the Mock Services tab, click Mock Services.
- Scroll down to the Mock Service Templates section and click the Add button.
- Give the Template a meaningful name.
Note: It is important to give meaningful names and descriptions, because when testers are using the Mock Services panel to add Mock Services to tests, they need to understand what might be relevant to their tests based on these values only.
- Select or create the associated Service. The Service is a representation of the underlying live service, and it serves as a container for the Transactions you will upload. If an existing Service contains Transactions that are needed for this Mock Service, select the existing Service.
To create a new Service:
- Click Select Service.
- Enter the name for your new Service and click Add Service.
- Click the arrow to the left of the Template name to edit Template details.
- Enter a description for the Template.
- (Optional) If the Transactions needed for the Template don't yet exist, drag a supported file type into the upload box. If the Transactions already exist in the Service you selected, skip to Step 10.
Note: If you want to upload multiple Swagger files using a zip file, the main file in the zip file must be named index.json or index.yaml for the upload to work.
The Import Transactions dialog opens.
- Select the Service that you specified in the Service field next to the Template name.
- If you want to assign one or more tags to these transactions, type the tag name(s) in the Tags field and press Enter.
- Tags make Transactions easier to identify, especially within a large Service. You can provide tag definitions here to apply the defined tags to all imported Transactions. Or you can define tags at the Transaction level after import.
- To enter multiple tags, press Enter after each tag name.
- Click Import.
The imported Transactions appear in the Other Transactions in Your Catalog pane.
- Select the Transactions to include in the Template, and click the right arrow icon to move them to the Transactions in this Mock Service Template panel.
- (Optional) Expand each Transaction in the Mock Service Template and enter values in the Priority field to control the matching order to follow when a request matches multiple Transactions.
The Transaction with the lowest number matches first. By default, all Transactions have the same Priority value, and a multiple matching scenario matches on the Transaction with the highest ID number.
Setting a priority for a Transaction only applies to that Transaction within the specific Template. In other Mock Services or Templates, the Transaction may have a different priority value.
- Click the Parameters tab.
- In the No Matching Requests field, choose the correct logic for when a request against the Mock Service does not match any of the provided transactions. The request can either throw an error or be redirected to the live service.
- Set the Think Time in milliseconds to control the amount of time spent between when the Mock Service receives a request and returns a response. The default is 0, but you can update the field to simulate delayed responses.
- Click Save.
Create a Mock Service from a Mock Service Template
At any time after saving the Template, click Create Mock Service to the right of the Template name to dynamically provision a Mock Service that includes the transactions in the Template.
- Go to the Mock Service Templates section.
- In the Actions column, click the Create Mock Service button.
Your Mock Service is created and you can find it in the Mock Services section.
Assign a Template to a Mock Service
You can assign a Template to a new or existing Mock Service at any time.
To assign a Template to a Mock Service:
- Navigate to a Mock Service and in the Actions column, click the icon for Assign Mock Service Template from this Mock Service:
- Select the Template to assign and click Apply.
The Template is assigned to the Mock Service. If the Mock Service already contained Transactions, they are overwritten by the Transactions in the Template.
Note: A template can be assigned to a Mock Service if the service is stopped or running. In either case, the transactions in the Mock Service will be overwritten with the transactions from the template assigned.
Create a Mock Service Template from a Mock Service
After you create a Mock Service with Transactions, you may realize that you need to reuse that Mock Service at a later date. Create a Template from the Mock Service to preserve its configuration for future use.
In the Actions column for the Mock Service, click the icon for Create Mock Service Template from this Mock Service to dynamically provision a Mock Service that includes the transactions in the Template:
A template is created with the same configuration as the Mock Service and you can find it in the Mock Service Templates section.