Learn
HELPER and SETUP
If a few tests need the same create step, put it in a HELPER and call it with SETUP:. Helpers don’t show up in the passed/failed count.
A helper, then a test
Same mock as POST. In the repo: examples/users/helpers.sapi.
SUITE: Users
URL: http://127.0.0.1:8765
HELPER: Create User
POST: /users
BODY: {"name": "Jane", "email": "jane@example.com"}
EXPECT: status == 201
SAVE: userId FROM $.id
TEST: Get User
SETUP: Create User
GET: /users/${userId}
EXPECT: status == 200
EXPECT: json $.email == "jane@example.com"
snapapi mock mock.json --port 8765
snapapi helpers.sapi
The tree only lists Get User. Create ran as setup:
SnapAPI Users
Get User
setup Create User
POST /users 201 4ms
saved userId=7
GET /users/7 200 1ms
PASS 5ms
1 passed 0 failed 5ms
1 passed is right — two HTTP calls, one test.
Don’t use TEST for setup
If you write TEST: Create User and then SETUP: Create User on another test, SnapAPI treats Create User as a helper and drops it from the count. Old suites still do that. New ones should use HELPER: for setup and TEST: for cases you want counted.
HELPER: is a setup procedure. It is not ${uuid()} or CALL.
The playground understands HELPER / SETUP too. Paste the suite with URL: mock://api if you want to try it there.