Skip to main content
Hooks let you run shell scripts before and after individual requests. Use @before for setup (seeding data, starting services) and @after for cleanup (removing test data, stopping services).

Security

Hooks execute shell scripts on your system. You must pass the --allow-shell flag to enable them. Without this flag, @before and @after hooks are skipped.

Basic Usage

@before Hooks

@before hooks run before the HTTP request is sent. Use them to prepare test data, start services, or set up preconditions.
Multiple @before hooks execute in the order they are declared.

@after Hooks

@after hooks run after the request completes and assertions are evaluated. They always run, even if the request or assertions fail. This makes them reliable for cleanup.
Multiple @after hooks also execute in declaration order.
@after hooks always run, even when the request fails or assertions do not pass. This guarantees cleanup happens regardless of test outcome.

Variable Resolution

Variables are resolved in hook paths and commands:

Execution Details

Example: Database Seed and Cleanup

scripts/seed-users.sh:
scripts/truncate-users.sh:

Example: Service Health Check

For simple command execution after a request (without needing a separate script file), consider using shell command blocks with the >>>shell syntax instead.
Last modified on February 9, 2026