Skip to content

scaf test

The test command runs scaf test files against your database.

Terminal window
# Run all .scaf files in current directory
scaf test
# Run specific file
scaf test queries/users.scaf
# Run multiple files
scaf test queries/users.scaf queries/posts.scaf
# Run all files matching pattern
scaf test ./queries/*.scaf

Output format for test results:

FormatDescription
dotsMinimal: . for pass, F for fail, S for skip (default)
verboseFull test names and timing
jsonStreaming JSON events for tooling
Terminal window
scaf test --format=verbose
scaf test -f json

Filter tests by path pattern:

Terminal window
# Run all tests in GetUser scope
scaf test --run="GetUser"
# Run specific group
scaf test --run="GetUser/existing users"
# Run specific test
scaf test --run="GetUser/existing users/finds Alice"
# Wildcard patterns
scaf test --run="*/edge cases/*"

Stop on first test failure:

Terminal window
scaf test --fail-fast

Override the configured database:

Terminal window
scaf test --database=neo4j
scaf test -d postgres

Number of tests to run concurrently (default: 1):

Terminal window
scaf test --parallel=4

Maximum time for each test:

Terminal window
scaf test --timeout=30s
scaf test --timeout=5m

Path to config file:

Terminal window
scaf test --config=./custom.scaf.yaml

Minimal output:

$ scaf test
.....
5 passed, 0 failed, 0 skipped (0.05s)
  • . — Pass
  • F — Fail
  • S — Skip
  • E — Error

Full test paths and timing:

$ scaf test --format=verbose
users.scaf
GetUser/existing users/finds Alice by id ... passed (0.01s)
GetUser/existing users/finds Bob by id ... passed (0.01s)
GetUser/edge cases/missing user ... passed (0.01s)
CountUsers/counts all users ... passed (0.01s)
4 passed, 0 failed, 0 skipped (0.04s)

Streaming newline-delimited JSON:

Terminal window
$ scaf test --format=json
{"time":"2024-01-15T10:30:00Z","action":"run","id":"users.scaf::GetUser::finds Alice"}
{"time":"2024-01-15T10:30:00Z","action":"passed","id":"users.scaf::GetUser::finds Alice","elapsed":0.012}
{"action":"summary","total":4,"passed":4,"failed":0,"skipped":0,"elapsed":0.05,"ok":true}

JSON events:

ActionDescription
runTest starting
passedTest passed
failedTest failed
skippedTest skipped
errorInfrastructure error
outputLog output
summaryFinal summary
CodeMeaning
0All tests passed
1One or more tests failed
2Configuration or connection error

When tests fail, scaf shows details:

$ scaf test --format=verbose
GetUser/finds Alice by id ... FAILED (0.01s)
field: u.name
expected: "Wrong Name"
actual: "Alice"
GetUser/age check ... FAILED (0.01s)
assertion failed: u.age >= 21
u.age = 18
0 passed, 2 failed, 0 skipped (0.02s)
Terminal window
# Run all tests with JSON output for parsing
scaf test --format=json > test-results.json
# Fail fast in CI
scaf test --fail-fast --format=verbose
Terminal window
# Run tests for the file you're working on
scaf test queries/users.scaf --format=verbose
# Run specific test while debugging
scaf test --run="GetUser/edge cases/missing user" --format=verbose
Terminal window
# Currently, use external tools
watchexec -e scaf -- scaf test