Skip to main content

Expectations & Assertions

What you'll learn
  • How to add assertions and expectations to HTTP scenarios with artillery-plugin-expect plugin
  • How to use the plugin to run functional tests for your API with Artillery


The expect plugin turns Artillery into a smoke / functional testing tool for HTTP APIs.


  • Use expectations and assertions in your HTTP scenarios
  • Use the same artillery command to run functional / acceptance tests on your APIs
  • See details of any failed assertions (request headers & body, response etc)
  • Run post-deployment smoke tests from CI/CD pipelines


Enable the plugin

To enable the plugin, add it to the config section of a test script.

target: ""
expect: {}

Add expectations to HTTP requests

- name: Get a movie
- get:
url: "/movies/5"
- json: "$.title"
as: title
- statusCode: 200
- contentType: json
- hasProperty: title
- equals:
- "From Dusk Till Dawn"
- "{{ title }}"

Try it live!

Run the test

Run your script that uses expectations with:

artillery run --quiet my-script.yaml

(The --quiet option is to stop Artillery from printing its default reports to the console.)

Run load + functional tests

This plugin allows for the same scenario to be re-used for either load testing or functional testing of an API, with the help of config.environments definition in your test script.

(The only real difference between the two, of course, is how many virtual users you run -- only one for functional tests, and lots of virtual users for a load test.)

target: "https://my.api.internal"
# This is our load testing profile, where we create a lot of virtual users.
# Note that we don't load the plugin here, so that we don't see the output
# from the plugin.
- duration: 600
arrivalRate: 10
# This is our functional testing profile, with a single virtual user, and
# the plugin enabled.
- duration: 1
arrivalCount: 1
expect: {}
# Your scenario definitions go here.

You could run the script above in load testing mode with:

artillery run --environment load script.yaml

and in functional testing mode with:

artillery run --environment functional script.yaml



The plugin supports a number of different output formats. The formatter may be set with the outputFormat config option.

The following formatters are available:

  • pretty (default) - prints HTTP method, URL for each request, along with each expectation
  • prettyError - only prints details of failed expectations
  • json - provides newline-delimited JSON output
  • silent - suppresses all output from the plugin (NOTE: this formatter is only available in v2 of the plugin)


Metrics support is available in v2 or later of the plugin.

The plugin tracks successful and failed expectations with custom metrics.

  • expect.ok - count of all expectations that have been successful
  • expect.failed - count of all expectations that failed
  • expect.ok.{type} - count of successful expectations of {type}, for example: expect.ok.statusCode for statusCode expectations
  • expect.failed.{type} - count of failed expectations of {type}, for example: expect.failed.statusCode for statusCode expectations



Check that the status code of the response.

- statusCode: 201

The value may also be a list to indicate that any of the codes in the list is OK:

- statusCode:
- 200
- 301


This check succeeds if the status code is anything but the list of codes specified.

For example, this expectation succeeds when the response status code is anything but 403 or 500:

- notStatusCode:
- 403
- 500


Check the value of Content-Type header.

hasProperty and notHasProperty

When the response is JSON, check that the response object has a property (or does not in case of notHasProperty). Same behavior as lodash#has.

- hasProperty: 'data[0].id'


Check that two or more values are the same. NOTE only primitive values (e.g. booleans, strings and numbers) are currently supported.

- get:
url: "/pets/f037ed9a"
- json: "$.species"
as: species
- equals:
- "{{ species }}"
- "dog"


Check that the response contains a header.

- get:
url: "/pets/f037ed9a"
- hasHeader: "object-version"


Check that the response contains a header and its value matches some string.

- get:
url: "/pets/f037ed9a"
- headerEquals:
- "object-version"
- "v3"

Multiple headers with the same name can also be matched. For example, if we expect a request to return two Set-Cookie headers with some known values we can check that they match like this:

- get:
url: "/protected/url"
- headerEquals:
# Expect two Set-Cookie headers returned by this request,
# in a particular order:
- set-cookie
- platform=astmh;version=1
- status=draft;version=1


Check that response body matches a regular expression. The regular expression provided must be a string which is a valid argument to the RegExp constructor.

- get:
url: "/pets/f037ed9a"
- matchesRegexp: .+ # body is not empty


This expectation checks for presence of a cache hit/miss header from a CDN. The following CDNs are supported:

  • Cloudflare
  • CloudFront
  • Fastly
  • Vercel

The check will succeed if:

  • A CDN cache hit/miss header is present in the response (one of cf-cache-status, x-cache, x-vercel-cache)
  • The value of the header is either hit or stale
- get:
url: "/pets/f037ed9a"
cdnHit: true


If you're having issues with the plugin, you can print out helpful debugging messages using the DEBUG environment variable.

Set DEBUG=plugin:expect when running your tests to view when using an expectation and any values to check.

DEBUG=plugin:expect artillery run my-script.yaml

More Information

The source code for artillery-plugin-expect is available on Github at It's an officially supported plugin and we'd love to hear your feedback and ideas for improvement.