Testkit
Testkit is a small language and CLI for operating, testing and proving apps (HTTP APIs, browsers and terminals), built by the APItoolkit team and amazing community contributors. The same one-line steps run from YAML files, the command line, a REPL and an MCP server, so people and LLM agents can drive an app, read it semantically and hand back a verifiable proof that a feature works.

Table of Contents
At a glance
- meta: { base_url: "http://localhost:${port}" }
- spawn: npm run dev # terminal surface: start the app
session: server
ready: for text /localhost:(\d+)/ or 60s
- extract: its match[1] into port
- visit: /login # browser surface
- fill: Email with "admin@acme.com" # bare names: the field / button with that name
- fill: Password with "${env.PASS}"
- click: Sign in
expect: the url ends with "/dashboard" # `expect:` works as a key on any step
- expect: no console errors
- claim: A user can create an order # a named proof
- click: New order
- fill: Customer with "Alice"
- click: Save
- expect: the status of request "POST /api/orders" is 201
- GET: /api/orders # API surface, same session cookies
cookies: from default
expect: [status is 200, json contains "Alice"]
$ testkit test # every *.tk.yaml under the current directory
$ testkit prove orders.tk.yaml # run it and write a receipt (GIFs, hashes, receipt.md)
$ testkit click 'button "Save"' # one step against a live CLI session
$ testkit mcp # the same grammar as an MCP server for agents
Installation
To install testkit, kindly follow one of the options below (click on the toggle):
Download Binaries
Navigate to the releases page, download the latest version of the testkit binary suitable for your operating system (Windows, macOS, or Linux), and proceed to install.
| Binary File |
Description |
testkit-release-test-i686-pc-windows-msvc.zip |
32-bit Windows (MSVC) |
testkit-release-test-x86_64-pc-windows-msvc.zip |
64-bit Windows (MSVC) |
testkit-release-test-x86_64-pc-windows-gnu.zip |
64-bit Windows (GNU) |
testkit-release-test-x86_64-apple-darwin.tar.gz |
64-bit macOS (Darwin) |
testkit-release-test-x86_64-unknown-linux-gnu.tar.gz |
64-bit Linux (GNU) |
After downloading, extract the zip file and proceed to install the extracted file. Alternatively, if you're using macOS, you can use Homebrew to install, like so:
Tap the testkit release repository to add it as a source for Homebrew formulae using the command below:
brew tap apitoolkit/testkit
Install testkit using the command below:
brew install testkit
Clone Repository
Kindly follow the steps below to build the project locally:
Ensure you have Rust programming language and Cargo package manager installed on your computer.
Clone the testkit repository from GitHub using the command below:
git clone https://github.com/testkit/testkit
Open the cloned directory using the command below:
cd testkit
Build the project using the Cargo command below:
cargo build --release
Once the build process is complete, you will find the testkit executable file in the target/release directory.
Run the testkit CLI tool, using the command below:
testkit test --file ./test.tk.yaml
For further testing, ensure to replace the ./test.tk.yaml with the path to your YAML test file.
[!NOTE]
Once testkit is installed succesfully, run the testkit --help command for all CLI commands and options.
Steps and expressions
A test file is a YAML list. Every item is one verb: expression; structured data (objects, lists, aria trees)
goes in sibling keys such as json:, with:, respond: or matches:. testkit grammar prints the full cheat sheet
(src/grammar.md); the design spec lives in the repository history.
- Locators follow the accessibility tree, like Playwright:
button "Sign in", field "Email", text "Welcome",
testid "checkout", <css/>, scoped with button "Edit" in row /Alice/. Actions also take a bare name:
click: Sign in (the interactive element with that name), fill: Email with "a@b.co" (that field).
In conditions a quoted string is visible text: expect: '"Order created"', no "Invalid password". Actions auto-wait for elements to be visible,
stable and enabled, and are strict: an ambiguous locator fails with a unique locator for every candidate.
- Expressions are hyperscript-flavoured:
json.id is 1043, the title is "Acme" (bare properties read the
previous step's result, or the page for title/url/path), the status of request "POST /api/orders" is 201,
no row /Alice/, the length of (orders where its status is "paid") is 2, name matches /^A/ ignoring case.
it is the previous step's result; ${var} and ${env.X} interpolate.
- Verbs cover the browser (
visit click fill check upload type press drag back reload), HTTP (GET POST PUT …),
terminals (exec spawn enter signal resize), flow (wait extract call route claim) and evidence (snapshot shot trace profile).
expect: retries until it passes, as a step or as a key on any step (expect: [status is 201, json.id is a Number]). Console and network subjects look at what happened since the last action,
and a run-wide guard fails a step that triggers a console error or an uncaught exception (allow: [console errors] to opt out).
- Structural checks:
expect: table "Orders" + matches: with a partial aria snapshot, expect: screen + lines,
expect: json + a partial JSON shape, or matches: golden/file.txt (--update-golden refreshes).
route: mocks responses for the browser and for API steps; call: flows/login.yaml composes files (with: in, exports: out).
A flow is also a step of its own: - login: as "admin@acme.com" with "${env.PASS}" runs flows/login.yaml, which
declares the phrase with - meta: { args: "as {user} with {pass}" }; unknown names fail before anything runs.
Driving an app from the CLI (and agents)
The first CLI step starts a background session daemon (--session name for more than one). Each command prints a
semantic step report: what appeared or disappeared, URL changes, network calls and console errors.
$ testkit visit http://localhost:3000/login # prints an aria snapshot with [ref=eN] refs
$ testkit fill @e3 --value admin@acme.com --record login.tk.yaml
$ testkit click 'button "Sign in"' --record login.tk.yaml
✓ click button "Sign in" 85ms
url /login → /dashboard
appeared heading "Dashboard" · alert "Welcome back" · navigation "Main"
network POST /api/session 200 · GET /api/me 200 1ms
$ testkit expect 'heading "Dashboard" is visible' --record login.tk.yaml
$ testkit find Orders · testkit explain '<expr>' · testkit observe network · testkit suggest
$ testkit repl # one step per line
$ testkit session attach http://localhost:9222 # drive your own running Chrome
Recording writes stable locators (refs become textbox "Email"), turns typed passwords into ${env.PASSWORD}, and
reuses variables for values it has seen. testkit mcp exposes step, snapshot, find, observe, claim and
receipt tools; testkit init --agents adds the grammar to AGENTS.md/CLAUDE.md and a skill file.
Proofs and receipts
claim: items split a file into named claims (steps before the first claim are setup). testkit prove file.tk.yaml
runs it without retries and writes .testkit/receipts/<id>/:
receipt.md: a status table per claim with an animated GIF, ready for a PR or an agent reply
receipt.html: a self-contained viewer with every step's screen, report and error
receipt.json: the manifest, including git SHA, environment, redactions and the sha256 of every artifact chained into one hash
Secrets that came from ${env.*}, cookies and auth headers are redacted before hashing. testkit receipt <id> --verify
detects any edited artifact. In a CLI session or over MCP: claim "…", steps, then claim end.
Performance and DevTools
the lcp of page, cls, inp, fcp, ttfb, the heap of page, the nodes of page, long tasks, a11y violations
are assertable. measure: true on an action records duration, visual, network and dom milestones.
trace: start / trace: stop into name and profile: write files DevTools opens; throttle: cpu 4x,
network: slow 3g and emulate: iPhone 15 | dark | reduced-motion change conditions. Baselines:
expect: the lcp of page is within 10% of baseline "home" after testkit baseline update file.tk.yaml; values near a
threshold are re-sampled and decided on the median.
CI
testkit test -o junit|tap|json|github (GitHub annotations point at the failing YAML line), -j 4, --shard 2/4,
--retries 1 (a pass after a retry is reported as flaky; --fail-on-flaky to fail), --repeat 20 to hunt flakes.
With CI=true the browser clock, timezone, randomness and animations are pinned. Exit codes: 0 pass, 1 failure,
2 invalid file or infrastructure error. testkit install chrome fetches Chrome for Testing when Chrome is missing.
Testkit tests itself
tests/tk/*.tk.yaml drive a fixture app (tests/app) and the testkit binary itself through exec:/spawn:: the CLI,
error messages, reporters, sessions and recording, the REPL, proofs and tamper detection, the MCP server, perf and
operations. cargo test runs them (TK_FILTER=05 cargo test --test selftest for one file); a failing claim there is a
gap in testkit. They need Python 3 and Chrome (set CHROME to its path if it isn't google-chrome/chromium or the macOS default).
Legacy API syntax
Files written for earlier versions keep working: {{var}}, $.env.X, $.resp.* JSONPath and typed asserts
(array:, numberAll:, contains: path ~ value …). testkit migrate file.yaml rewrites {{x}} / $.env.X to ${…}, select: to fill:, and asserts: lists of only ok: to expect:.
The original reference follows.
Test Definition Syntax
Testkit uses a YAML-based syntax for defining test scenarios. Each scenario consists of multiple stages, where each stage represents a specific API request and its associated assertions. Below is an example of the YAML syntax for defining API tests:
---
- title: fetches TODO items - GET
GET: /todos/
asserts:
- ok: $.resp.status == 200
- array: $.resp.json
exports:
todoItem: $.resp.json[0]._id
- title: deletes TODO items - DELETE
DELETE: /todos/$.stages[0].todoItem
asserts:
- empty: $.resp.json.todos
- string: $.resp.json
- title: Adds Todo item - POST
POST: /todos/
json:
task: "run tests"
asserts:
- ok: $.resp.status == 200
- ok: $.resp.json.task == "run tests"
- ok: $.resp.json.completed
In the example above, the YAML test file defines three test items fetching TODO items using a GET request, deleting a specific TODO item using a DELETE request, and adding a new TODO item using a POST request. The YAML file consists of a list of test scenarios. Each scenario represents an API request and contains the following fields:
| Field |
Description |
title (required) |
A descriptive name for the stage. |
request (required) |
Defines the API request to be made, including HTTP methods and the URL. |
asserts (optional) |
Optional. Defines assertions to be performed on the response for validation. |