@depends directive lets you declare explicit dependencies between requests, ensuring that prerequisite requests run first regardless of file order.
Basic Usage
Add# @depends <requestName> to any request that relies on another:
getProfile request will always execute after login, even if you run tests in parallel mode or filter to a specific request.
Multiple Dependencies
A request can depend on multiple other requests. Separate names with commas:--parallel is enabled).
How It Works
Topological Sort
hitspec builds a directed acyclic graph (DAG) from the@depends declarations and performs a topological sort to determine execution order. This means:
- Dependencies always run before the requests that need them
- Independent requests can run in any order
- With
--parallel, independent requests run concurrently
login and setupDb can run in parallel, getProfile and createPost must wait for their dependencies, and verifyPost runs last.
Cycle Detection
hitspec detects circular dependencies at parse time and reports an error:Cross-File Dependencies
Dependencies work across files within the same test run. Iflogin is defined in auth.http and createPost in posts.http, you can still declare:
Implicit Dependencies via Captures
Using a captured variable implicitly requires the capturing request to run first, but hitspec does not infer this automatically. You must always declare@depends explicitly:
Without
@depends, hitspec may execute requests in any order (especially with --parallel), causing captured variable references to resolve to empty strings.Dependency Chains
Dependencies are transitive. If A depends on B and B depends on C, then A implicitly waits for both B and C:# @depends createOrg, createTeam on addMember — depending on createTeam is sufficient because createTeam already depends on createOrg.
Parallel Execution with Dependencies
When you run tests with--parallel, hitspec respects all @depends constraints while maximizing concurrency for independent requests:
- Requests with no dependencies start immediately
- Requests with satisfied dependencies start as soon as their prerequisites complete
- The
--concurrencyflag limits how many requests run simultaneously
Filtered Execution
When you filter tests by name or tag, hitspec automatically includes any dependency that the filtered request needs:Common Patterns
Setup and Teardown
Fan-Out Pattern
Multiple requests depend on a single setup step:--parallel, the three test requests run concurrently after login completes.