Creating a Mock Service Template

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

Follow these steps:

  1. Log into your BlazeMeter account.
  2. In the Mock Services tab, click Mock Services.
  3. Scroll down to the Mock Service Templates section and click the Add button.
    templates
  4. Give the Template a meaningful name.
    Note: It is important to give meaningful names and descriptions, because when testers are using the Mock Services pane to add Mock Services to tests, they need to understand what might be relevant to their tests based on these values only.
  5. 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:
    1. Click Select Service.
    2. Enter the name for your new Service and click Add Service.
  6. Click the arrow to the left of the Template name to edit Template details.
  7. Enter a description for the Template.
  8. (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.
    file upload
    The Import Transactions dialog opens.
    import dialog
  9. Select the Service that you specified in the Service field next to the Template name.
  10. 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.
  11. Click Import.
    The imported Transactions appear in the Other Transactions in Your Catalog pane.
  12. 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 pane.

    Tip: You can use a quick action to move transactions with a single click. Click the Include this transaction in the Mock Service icon in the left column. To remove a transaction from the Mock Service, you can click the Remove this transaction from the Mock Service icon in the right column. Click to enlarge the screenshots.
    a quick way to include transactions

    a quick way to remove transactions

  13. (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.
    priority value transaction template
    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.
  14. Click the Parameters tab.
  15. 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.
  16. 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 of a fixed length in milliseconds, or define a randomized Think Time with Lognormal or Uniform distribution within bounds.
  17. 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.

  1. Go to the Mock Service Templates section.
  2. In the Actions column, click the Create Mock Service button.
    create mock service from template

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.

actions column

To assign a Template to a Mock Service:

  1. Navigate to a Mock Service and in the Actions column, click the icon for Assign Mock Service Template from this Mock Service:
    the Assign action icon
  2. 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.

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.

the actions column in the UI

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:

the Create Template action icon

A template is created with the same configuration as the Mock Service and you can find it in the Mock Service Templates section.