> ## Documentation Index
> Fetch the complete documentation index at: https://docs.ubiquex.io/llms.txt
> Use this file to discover all available pages before exploring further.

# test

> The test block defines automated tests that instantiate a module and assert on its results.

The `test` block defines an automated test that instantiates a module under test and asserts on the resulting values. Tests are run by [`ubx test`](/v1/cli/test) and conventionally live in `*.test.xcl` files.

## Syntax

```xcl theme={"theme":"css-variables","languages":{"custom":["/languages/xcl.json"]}}
test name {
  binding = module "modname" {
    source = "./path/to/module"
    // input values
  }

  assert {
    condition     = <boolean expression>
    error_message = <string expression>
  }
}
```

The label is a bare identifier, quotes optional. A quoted label may contain spaces.

## Fields

| Field                        | Description                                                                                                                                                             |
| ---------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `<binding> = module "…" { }` | Instantiates a module under test. The `source` field is required; every other field is passed to the module as an input. The binding name exposes the module's outputs. |
| `assert { }`                 | An assertion block. One or more may appear. See [assert](#assert-blocks).                                                                                               |

## Assert blocks

Each `assert` block has exactly two required fields:

| Field           | Description                                                             |
| --------------- | ----------------------------------------------------------------------- |
| `condition`     | A boolean expression that must evaluate to `true` for the test to pass. |
| `error_message` | A string expression reported when the condition is `false`.             |

<Note>
  All `assert` blocks in a test are evaluated and every failure is reported — the runner does not stop at the first failure.
</Note>

## Example

```xcl theme={"theme":"css-variables","languages":{"custom":["/languages/xcl.json"]}}
test vpc_defaults {
  net = module "networking" {
    source   = "./modules/networking"
    vpc_cidr = "10.0.0.0/16"
  }

  assert {
    condition     = net.vpc_cidr == "10.0.0.0/16"
    error_message = "VPC CIDR should match the input"
  }
}
```

## Running tests

Run all tests in a directory with [`ubx test`](/v1/cli/test). Each `test` block instantiates its module, evaluates every `assert`, and reports any failures.
