Official GitHub Action
The fastest way to add hitspec to your pipeline:.github/workflows/api-tests.yml
Action Inputs
| Input | Description | Default |
|---|---|---|
files | Files or directories to test | (required) |
env | Environment name | dev |
env-file | Path to .env file | - |
output | Output format (console, json, junit, tap) | junit |
output-file | Write output to file | - |
tags | Filter by tags | - |
parallel | Run in parallel | false |
bail | Stop on first failure | false |
stress | Enable stress testing | false |
duration | Stress test duration | 30s |
rate | Requests per second | 10 |
threshold | Pass/fail thresholds | - |
version | hitspec version to install | latest |
Using the CLI Directly
If you prefer installing hitspec yourself (for example, to pin a specific version or use Homebrew caching), you can call the CLI directly:.github/workflows/api-tests.yml
Exit Codes
hitspec uses specific exit codes that GitHub Actions interprets as pass or fail:| Code | Meaning | CI Result |
|---|---|---|
0 | All tests passed | Step passes |
1 | One or more tests failed | Step fails |
2 | Parse error (invalid .http file syntax) | Step fails |
3 | Configuration error | Step fails |
4 | Network/connection error | Step fails |
64 | Invalid CLI usage | Step fails |
Environment Variables and Secrets
Use GitHub secrets to pass sensitive values like API tokens and credentials. hitspec supports all major CLI flags as environment variables with theHITSPEC_ prefix.
Using an .env File
If your tests rely on an environment file, generate it from secrets at runtime:
Supported Environment Variables
| Environment Variable | CLI Flag | Description |
|---|---|---|
HITSPEC_ENV | --env | Environment to use |
HITSPEC_ENV_FILE | --env-file | Path to .env file |
HITSPEC_CONFIG | --config | Path to config file |
HITSPEC_TIMEOUT | --timeout | Request timeout |
HITSPEC_TAGS | --tags | Filter by tags |
HITSPEC_OUTPUT | --output | Output format |
HITSPEC_OUTPUT_FILE | --output-file | Output file path |
HITSPEC_BAIL | --bail | Stop on first failure |
HITSPEC_PARALLEL | --parallel | Run in parallel |
HITSPEC_CONCURRENCY | --concurrency | Concurrent requests |
HITSPEC_QUIET | --quiet | Suppress output |
HITSPEC_NO_COLOR | --no-color | Disable colors |
HITSPEC_PROXY | --proxy | Proxy URL |
HITSPEC_INSECURE | --insecure | Skip SSL verification |
Caching
Cache the hitspec binary to speed up subsequent runs:Matrix Testing
Run the same tests across multiple environments or configurations using a GitHub Actions matrix:.github/workflows/api-tests.yml
Matrix with Tags
You can also use a matrix to run different test suites:Stress Testing in CI
Run load tests in your pipeline to catch performance regressions:threshold input defines pass/fail criteria. If any threshold is exceeded, the step fails with exit code 1.
Reporting with JUnit
Most CI reporting tools understand JUnit XML. To publish results in GitHub pull requests, combine hitspec with a JUnit reporter action:Full Example Workflow
A complete workflow that runs smoke tests on every PR, full tests onmain, and uploads results:
.github/workflows/api-tests.yml