For the complete documentation index, see llms.txt. Markdown versions of documentation pages are available by appending .md to page URLs.
Skip to content

Unit tests

Unit tests: YAML fixtures for inputs and outputs, testing incremental models and CTEs, and running tests with the CLI.

Unit tests are your safety net for data transformations. You write them to verify that your models transform data correctly, catching problems before they reach production.

Unit tests are executable documentation. They show how your model should behave with specific inputs, and they fail if something changes unexpectedly. Unlike assertions (which check data quality at runtime), unit tests verify the logic of your models against predefined inputs and expected outputs.

Why testing matters

Small errors in data models cascade into big problems downstream. Why testing is worth your time:

  • Catch breaking changes: refactor with confidence. Tests flag unintended behavior changes.

  • Document expected behavior: tests serve as executable specifications (better than comments that get outdated).

  • Faster debugging: when something breaks, tests pinpoint which transformation failed.

  • Calculation correctness: verify that aggregations, joins, and calculations produce the expected results for known inputs.

  • Confidence in changes: make updates knowing you'll catch regressions before they hit production.

Tests run on demand (such as in CI/CD pipelines) or automatically when you create a new plan.

Creating tests

Tests live in YAML files in the tests/ folder of your project. The filename must start with test and end with .yaml or .yml. You can put multiple tests in one file.

At minimum, a test needs 3 things:

  • model: which 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).

Start with a simple example.

Your first test

Here is a model that aggregates orders by date:

Write a test to verify it works correctly:

This test gives the model 3 orders (2 on March 15, 1 on March 16) and checks that:

  • Orders are correctly grouped by date

  • total_orders counts distinct orders per day (should be 2 for March 15, 1 for March 16)

  • total_revenue sums the amounts correctly (50 + 75 = 125 for March 15)

  • last_order_id returns the maximum order ID per day (O002 for March 15, O003 for March 16)

If any of these expectations do not match, the test fails and tells you what went wrong.

Testing models with multiple dependencies

Real-world models often join multiple tables. Here is how to test a more complex model that joins customers, orders, and order items:

The test provides mock data for all 3 upstream tables. It verifies that the model:

  • Joins customers with orders and order items

  • Counts distinct orders per customer

  • Calculates total spent (quantity × unit_price summed across all items)

  • Handles division by zero (Charlie has no orders, so avg_order_value should be NULL)

The comments in the YAML explain the test data, which makes it easier to understand what is being tested.

Testing incremental models

Incremental models filter data by time range. Set start and end dates using the vars attribute:

The vars section tells Vulcan what time range to use when running the model. Incremental models filter by @start_ds and @end_ds macros, and you need to control those in your test.

Testing CTEs

You can test individual CTEs (Common Table Expressions) within your model. Use this to debug complex queries step by step.

Suppose you have a model with a CTE:

You can test both the CTE and the final query:

This verifies that:

  1. The CTE correctly filters to item_id = 1 (should return rows with id 1 and 2)

  2. The final query correctly counts distinct orders (should be 2)

Testing CTEs separately makes it easier to pinpoint where things go wrong in complex queries.

Supported data formats

Vulcan supports several formats for test data. Pick whichever format fits your situation:

YAML dictionaries (default)

The most common format. List your rows as YAML dictionaries:

This works well for small datasets and when you want everything in one place.

CSV format

If you have lots of data, CSV is often easier to read and write:

You can customize CSV parsing with csv_settings if you need different separators or other options.

SQL queries

Use a SQL query when you want more control over how data is generated:

Use this when you need to generate test data programmatically or when the data structure is complex.

External files

For large test datasets, store them in separate files:

This keeps your test files clean and makes it easy to reuse test data across multiple tests.

Omitting columns

For wide tables, you do not need to specify every column. Omit columns (Vulcan treats them as NULL) or use partial matching to only test the columns you care about:

Use this when you have a table with 50 columns but only care about testing a few of them.

Apply partial matching globally:

This applies partial matching to all outputs in the test. Useful when you only test a subset of columns.

Freezing time

If your model uses CURRENT_TIMESTAMP or similar functions, freeze time in your tests to make them deterministic. Otherwise, your tests fail every time you run them because the timestamp changes.

Setting execution_time in vars makes CURRENT_TIMESTAMP and CURRENT_DATE return fixed values, so your tests are predictable and repeatable.

Running tests

How to invoke tests and read what they print.

Command line

Run tests from the command line:

The :: syntax lets you run a specific test from a file when debugging a single failing test.

Example output

When tests pass, you see something like:

The dots (.) indicate passing tests.

When tests fail:

The output shows what did not match. In this case, total_orders was expected to be 3.0 but was actually 2.0. This tells you what to investigate.

Automatic test generation

Writing tests can be tedious, especially when you are getting started. Vulcan can generate tests automatically:

This creates a test file with actual data from your warehouse, which makes it easy to bootstrap your test suite. You can then tweak the generated test to match your needs.

Tip: start with generated tests, then refine them to test edge cases and specific scenarios. This is much faster than writing everything from scratch.

Troubleshooting

Common problems and how to work through them.

Preserving fixtures

When a test fails, inspect the actual data it created. Use --preserve-fixtures to keep test fixtures:

Vulcan creates fixtures as views in a schema named vulcan_test_<random_ID>. Query these views directly to see what data they produced for debugging.

Type mismatches

Sometimes Vulcan cannot figure out the correct types for your test data. If you see type errors, specify them explicitly:

The columns section tells Vulcan what types to use, which avoids type inference issues. You can also explicitly cast columns in your model's query to help Vulcan infer types more accurately.

Test not finding model

Problem: test says it cannot find the model.

Solution: make sure the model name in your test matches exactly what is in your models/ folder. Model names are case-sensitive and must include the schema (such as sales.daily_sales, not just daily_sales).

Output order matters

Problem: test fails even though the data looks correct.

Solution: the columns in your expected output must appear in the same order as the model's query selects them. Check the SELECT statement order and make sure your test rows match.

Partial matching not working

Problem: partial matching is not ignoring extra columns.

Solution: set partial: true at the right level. It needs to be under outputs.query (or outputs.ctes.<cte_name>) for CTE-specific partial matching, or under outputs for global partial matching.

Test structure reference

A complete reference of all the fields you can use in a test. Most tests only need model, inputs, and outputs.

<test_name>

The unique name of your test. Use descriptive names that explain what you are testing, such as test_daily_sales_aggregation or test_customer_revenue_calculation.

<test_name>.model

The fully qualified name of the model being tested (such as sales.daily_sales). This model must exist in your project's models/ folder.

<test_name>.description

An optional description that explains what the test validates. This helps your teammates (and future you) understand what the test checks.

<test_name>.schema

The name of the schema that contains the test fixtures (the views created for this test). If not specified, Vulcan creates a temporary schema.

<test_name>.inputs

Mock data for upstream models that your target model depends on. If your model has no dependencies, omit this.

<test_name>.inputs.<upstream_model>

A model that your target model depends on. Provide mock data for each upstream model.

<test_name>.inputs.<upstream_model>.rows

The rows of test data, defined as an array of dictionaries:

Shortcut: If rows is the only key, you can omit it:

<test_name>.inputs.<upstream_model>.format

The format of the input data. Options: yaml (default) or csv.

<test_name>.inputs.<upstream_model>.csv_settings

When using CSV format, customize how the CSV is parsed:

See pandas read_csv documentation for all supported settings.

<test_name>.inputs.<upstream_model>.path

Load data from an external file:

<test_name>.inputs.<upstream_model>.columns

Specify column types explicitly to help Vulcan interpret your data correctly:

This is especially useful when Vulcan cannot infer types correctly (such as with dates or decimals).

<test_name>.inputs.<upstream_model>.query

Generate input data using a SQL query:

Note: you cannot use query together with rows. Pick one or the other.

<test_name>.outputs

The expected outputs from your model. This is what you assert should be true.

Important: column order matters. The columns in your expected rows must match the order they appear in the model's SELECT statement.

<test_name>.outputs.partial

When true, only test the columns you specify. Vulcan ignores extra columns in the output. Useful for wide tables where you only care about a few columns.

<test_name>.outputs.query

The expected output of the model's final query. Optional if you test CTEs instead.

<test_name>.outputs.query.partial

Same as outputs.partial, but applies only to the query output (not CTEs).

<test_name>.outputs.query.rows

The expected rows from the model's query. Same format as input rows.

<test_name>.outputs.query.query

Generate expected output using a SQL query. Useful when the expected output is complex or you want to compute it dynamically.

<test_name>.outputs.ctes

Test individual CTEs within your model. Optional if you test the final query output.

<test_name>.outputs.ctes.<cte_name>

The expected output of a specific CTE. Use this to test intermediate steps in complex queries.

<test_name>.outputs.ctes.<cte_name>.partial

Partial matching for a specific CTE.

<test_name>.outputs.ctes.<cte_name>.rows

Expected rows for a specific CTE.

<test_name>.outputs.ctes.<cte_name>.query

Generate expected CTE output using a SQL query.

<test_name>.vars

Set values for macro variables used in your model:

Special variables:

  • start: overrides @start_ds for incremental models.

  • end: overrides @end_ds for incremental models.

  • execution_time: overrides @execution_ds and makes CURRENT_TIMESTAMP and CURRENT_DATE return fixed values.

Use these for testing incremental models and making time-dependent tests deterministic.

Last updated

Was this helpful?