Quick start

From nothing to a passing test in five minutes.

Everything here uses the free, open source command line tool. The Mac app reads the same files, and you can add it later or never.

1. Install it

brew install stampdrill/tap/stampdrill

Both stampdrill and the shorter stamp are installed, and they are the same program. On Linux, or without Homebrew, download a static binary from the releases page; it needs nothing else installed.

2. Write a request

Make a folder, and put this in api.stamp. A workspace is just a folder of these files.

### Posts
GET https://jsonplaceholder.typicode.com/posts?_limit=5

> assert status == 200
> assert body.length == 5
> assert time < 2000, "that took " + time + " ms"
stamp run api.stamp

The response comes back with the check next to it. assert lines decide the exit code, so this already works in a pipeline.

3. Bring what you already have

If there is a Postman, Insomnia or Bruno collection lying around, convert it instead of retyping it. Environments come across as variables, and anything that looks like a token goes into environment.local.stamp, which stays out of git.

stamp import collection.json qa.postman_environment.json -o api
stamp check api
stamp list api

4. Add variables that follow your environments

Put this in environment.stamp beside the requests. A dimension is one axis your setup varies along, here the environment you are pointing at. You name its values once, each vars block says which of them it applies to, and the value you pick when you run decides which variables you get.

dimension env = test, staging, prod

vars {
  baseUrl = localhost(3000)
  limit = 5
}

vars env=staging {
  baseUrl = "https://api.staging.example.com"
}

vars env=prod {
  baseUrl = "https://api.example.com"
  limit = 25
}
stamp run api.stamp env=staging

5. Chain requests and check the result

set hands a value to later requests, and @needs makes sure the thing it came from has run.

### Log in
@name logIn
POST {{baseUrl}}/login
Content-Type: application/json

{ "username": "{{username}}", "password": "{{password}}" }

> assert status == 200
> set token = body.token

### My orders
@needs logIn
@auth bearer {{token}}
GET {{baseUrl}}/orders?limit={{limit}}

> assert all(body.items, order => order.total > 0)

6. Turn it into a test plan

Plans go before the first request in a file. They run steps in order, over a matrix of dimensions or a row of CSV at a time, with loops and conditions where you need them.

plan Checkout {
  tags smoke
  matrix env = staging|prod
  retry 2 every 500ms

  step "Browse" {
    run listProducts
    expect status == 200
    set productId = body[0].id
  }

  for each quantity in [1, 3] {
    step "Add to the basket" {
      run addToBasket with id = productId, quantity = quantity
      expect body.items.length > 0
    }
  }

  if env == "prod" {
    step "Prices carry tax" {
      run basket
      expect body.tax > 0
    }
  }
}
stamp test .                          # every plan
stamp test . --tags smoke             # only the ones tagged smoke
stamp test . --junit reports/junit.xml

7. Put it under load

A load test lives in the same file as the requests it drives. Thresholds decide the exit code, so a slow release fails the build like a broken test would.

load BusyMorning {
  users 20
  ramp 10s
  duration 1m
  think 200ms..1s
  seed busy-morning
  threshold p95 < 800ms
  threshold errors < 1%
  scenario {
    run listProducts
    run getProduct
  }
}
stamp load .

8. Run it in CI

- name: API tests
  run: |
    curl -sL https://github.com/stampdrill/stampdrill/releases/latest/download/stampdrill-linux-x86_64.tar.gz | tar xz
    ./stamp test api --junit reports/junit.xml

Exit codes: 0 everything passed, 1 a check or threshold failed, 2 a file has errors.

Where to go next