Introduction
Tests in XanoScript allow you to define automated testing for your application logic. Unlike other primitives, tests come in two different types, each serving different testing purposes. XanoScript supports two types of tests:- Unit tests — Test a single function stack or primitive
- Workflow tests — Test multiple functions or APIs together in sequence
Anatomy
Every XanoScript test follows a predictable structure, though the specific components vary by test type. Here’s a quick visual overview of the main building blocks — from declaration at the top to expectations at the bottom.You can find more detail about each section by continuing below.
Declaration
Every test starts with a declarative header that specifies its type, name, and description.XanoScript
Element | Required | Description |
---|---|---|
test_type | ✅ | Declares the test primitive type (test or workflow_test ). |
test_name | ✅ | The unique name for the test. |
description | no | Optional human-readable description of the test’s purpose. |
Test Types
Unit Tests
Unit tests are embedded within the primitive they’re testing and focus on testing a single function stack or API endpoint.XanoScript
- Embedded — Live inside the primitive being tested
- Single focus — Tests one function stack or API
- Simple input — Uses direct input values
- Response testing — Tests the response from the primitive
Workflow Tests
Workflow tests are standalone primitives that can test multiple functions or APIs together in sequence.XanoScript
- Standalone — Independent primitive
- Multi-step — Can test multiple functions/APIs in sequence
- Complex logic — Uses full stack with multiple operations
- Sequential testing — Tests can build on previous results
Section 1: Configuration
The configuration section defines how the test should run and what data to use.Unit Test Configuration:Workflow Test Configuration:Configuration Options:
XanoScript
XanoScript
datasource
— Specifies which datasource to use for testing ("live"
,"draft"
, etc.)input
— Test input data (unit tests only)tags
— Categorization tags (workflow tests only)
Section 2: Stack/Input
This section varies significantly between test types.Unit Test Input:Workflow Test Stack:Key Differences:
XanoScript
XanoScript
- Unit tests use simple
input
objects - Workflow tests use full
stack
blocks with multiple operations - Workflow tests can call APIs, functions, and other primitives
- Workflow tests can test multiple scenarios in sequence
Section 3: Expectations
The expectations section defines what the test should verify.Expectation Syntax:Common Expectation Methods:
XanoScript
expect.to_be_defined
— Verifies a value exists and is not null/undefinedexpect.to_not_be_defined
— Verifies a value is null/undefinedexpect.to_equal
— Verifies a value equals an expected resultexpect.to_not_equal
— Verifies a value does not equal an expected resultexpect.to_contain
— Verifies a value contains expected contentexpect.to_be_true
— Verifies a value is trueexpect.to_be_false
— Verifies a value is false
- Unit tests — Expectations are defined after the input configuration
- Workflow tests — Expectations can be placed anywhere in the stack
Settings
Test primitives support optional settings for organization and configuration.Setting | Type | Required | Description |
---|---|---|---|
description | string | no | A human-readable description of the test’s purpose. |
datasource | string | no | Specifies which datasource to use for testing. |
input | object | no | Test input data (unit tests only). |
tags | array[string] | no | A list of tags used to categorize and organize the test. |
"live"
— Uses the live datasource for testing"draft"
— Uses the draft datasource for testing- Other datasource names as configured in your workspace
Detailed Examples
Unit Test Examples
XanoScript
Workflow Test Example
XanoScript
What’s Next
Now that you understand how to define tests in XanoScript, here are a few great next steps:Explore the function reference
Learn about the built-in functions available in the stack to start writing more complex test logic.
Try it out in VS Code
Use the XanoScript VS Code extension with Copilot to write XanoScript in your favorite IDE.
Learn about APIs
Create APIs that you can test with your unit and workflow tests to ensure robust functionality.