Skip to main content
Tests live beside the code they cover and ship with it. There are two kinds: expect.* builds an assertion record and s.expect.* builds a statement. They are not interchangeable, and the types enforce it.

A unit test

Each entry is a named set of inputs run against that object:
Any statement can take a mock keyed by test name, which returns a value instead of doing its work while that one test runs:

On a tool, prompt or resource

tool(), prompt() and resource() take tests the same way. The test’s input is the tool’s input, the prompt’s arguments or the resource’s URI variables:
They run with the rest of the suite, named tool:<name>/<test> (prompt: and resource: for the others). A pull brings them back with their mocks, so a deploy from a pulled tree keeps tests written in the Xano editor.
A backend on an engine older than tests on these kinds lists none of them, so the suite passes without running them. Check npx @xano/sdk test list when a tool’s tests seem to be missing.

A workflow test

A workflow test calls other objects and asserts on what they bind:
Register them with .registerFunctions([addNote]) and .registerWorkflowTests([addNoteWorks]). A workflow test can run another with s.workflow_test.call, and export() fails with reference.unresolved when the one it calls is not registered.
  • s.expect.* takes one argument object, with the subject as expr: { expr } for a subject-only assertion such as to_be_defined, { expr, value } for one with an operand such as to_equal, { expr, min, max } for to_be_within, and { body, exception? } for to_throw, where body is the statements expected to fail.
  • Four calls run only here. s.api.call, s.task.call, s.trigger.call and s.workflow_test.call work only in a workflowTest() stack. In a query, function or task the engine cannot reach the target, so export() refuses them there. s.function.call runs from any stack.
  • A failing call does not always raise. s.api.call binds a stack error’s { code, message, payload } to as and the test carries on, so assert on ref("r.code") when a call may fail.
Both kinds run against an empty datasource by default, so no seed rows exist while a test runs. Create what the test needs first (a function the stack calls), or mock the read. Setting datasource: "live" reads seed rows on an ephemeral, but the value is stored on the object: clear it before you promote, or the test clones your real database.

Run them

Tests run against what is deployed, so deploy first:
With no flag, test runs on the backend this project last deployed to. --on names another:
--on workspace runs against your real database. That is safe only while every test keeps the default empty datasource.

Deploy and test in one step

--test runs the suite after a deploy, against what it just shipped. This is the first step of the release flow:
--json (or a stdout that is not a terminal) prints one JSON document naming each test and its status, so CI can report which test failed. See CI/CD and exit codes.

Next