Unit Test
Unit tests verify a model's SQL logic against mock fixtures, independent of any warehouse, before assertions or a real run ever see it.
A unit test checks a model's transformation logic. It runs the model's SQL against fixtures: inputs and expected outputs that you write by hand. No warehouse is involved.
This is different from an assertion. An assertion checks real data after a model runs. A test checks the model's logic before that, using fixed, fake data you control.
Tests fit alongside the other data quality tools in Vulcan. Here's the mental model to hold onto: unit tests validate logic, audits define a rule, assertions attach that rule to a model and block bad data, and DQ checks watch data over time and warn without blocking.
Applied to tests specifically: a test proves the model's SQL produces the right output for a given input. An audit is a reusable rule. An assertion attaches that rule to a model. A DQ check monitors quality over time.
Tests run on demand, such as in a CI/CD pipeline. They also run automatically whenever you apply a plan.
Creating tests
Tests live in YAML files in the tests/ folder. The filename must start with test and end in .yaml or .yml. You can put multiple tests in one file.
At minimum, a test needs 3 keys:
model: the model you are testing.inputs: mock data for upstream dependencies (what goes in).outputs: expected results from the model's query (what should come out).
orders-analytics has 2 tests:
test_fct_daily_sales_excludes_cancelled_orderschecks a core business rule: canceled orders must not count toward revenue insilver.fct_daily_sales. The@revenue_order_filtermacro enforces this rule.test_rfm_customer_segmentation_championchecks that a customer with top recency, frequency, and monetary scores lands in the Champions segment ingold.rfm_customer_segmentation.
test_fct_daily_sales_excludes_cancelled_orders:
model: silver.fct_daily_sales
inputs:
bronze.orders:
- order_id: 1
customer_id: 10
order_date: '2026-01-01 10:00:00'
warehouse_id: 100
order_status: Shipped
- order_id: 2
customer_id: 10
order_date: '2026-01-01 11:00:00'
warehouse_id: 100
order_status: Cancelled
bronze.customers:
- customer_id: 10
region_id: 1
name: Avery Stone
email: avery.stone@example.com
signup_date: '2025-12-01'
bronze.regions:
- region_id: 1
region_name: North
bronze.order_items:
- order_id: 1
item_id: 1
product_id: 200
quantity: 2
unit_price: 10.00
- order_id: 2
item_id: 1
product_id: 200
quantity: 5
unit_price: 10.00
bronze.products:
- product_id: 200
supplier_id: 300
name: Widget Basic
category: Widgets
price: 10.00
outputs:
query:
partial: true
rows:
- customer_id: 10
total_orders: 1
total_revenue: 20.00Two orders go in: one Shipped, one Canceled.
The Canceled order's items (quantity 5, value 50.00) never reach the output. The single expected row shows total_orders: 1 and total_revenue: 20.00, from the Shipped order alone.
partial: true means Vulcan only checks the listed columns. It ignores the model's other output columns.
Set <test_name>.schema to name the schema where Vulcan creates the test's fixture views, if you need it somewhere other than the default temp schema.
Key capabilities
Multiple dependencies - provide mock rows for every upstream model the target joins, listed side by side under
inputs, exactly as the example above does for five bronze tables.Incremental models - set
vars.startandvars.endto control the@start_ds/@end_dsmacros an incremental model reads.Testing CTEs - assert on an intermediate CTE via
outputs.ctes.<cte_name>.rows, so you can debug a complex query step by step instead of only checking the final result.Data formats - input rows default to YAML. Use
format: csv(tune withcsv_settings), a SQLquery, orpathto an external file instead.queryandrowsare mutually exclusive on the same input.Partial matching - set
partial: true, at eitheroutputs.partialoroutputs.query.partial, to check only the columns you list; Vulcan ignores the rest.Freezing time - set
vars.execution_timeso a model usingCURRENT_TIMESTAMP/CURRENT_DATEproduces the same result every run.Explicit column types - if Vulcan infers the wrong type for a mock column, declare it under
inputs.<model>.columns.Automatic generation - bootstrap a test from real data with
vulcan create_test <model> --query <upstream> "<sql>", then refine the fixture by hand.
For the full syntax of each of these, see the reference link at the end of this page.
Running tests
In orders-analytics, vulcan test runs both tests:
Each dot (.) is a passing test.
A failing test prints a diff of expected (exp) versus actual (act) rows. Fix the model or the expectation, then re-run.
A test proves the model's logic is right before any warehouse run ever sees it. For the full test-key reference, csv_settings options, and troubleshooting tips, see References → Vulcan → Quality → Unit Test.
Last updated
Was this helpful?