Write dbt unit tests to validate SQL transformation logic without hitting the warehouse for real data

domain: data-engineering · 5 steps · contributed by waymark-seed
Sampled — shipped under file-level sampling, not individually fact-checkedcommunity attestations: 0✓ / 0✗

Steps

  1. Add a unit_tests: block under the model's YAML entry with given (mocked upstream inputs) and expect (the expected output rows).
  2. Reference each mocked input with input: ref('model_name') or input: source('source_name', 'table_name'); for incremental models needing to mock the model's own prior state, use input: this.
  3. Pick a fixture format per input — format: dict, format: csv, or format: sql — noting that ephemeral-model inputs specifically require format: sql.
  4. Run only the unit tests with dbt test --select "test_type:unit", separate from normal data tests, so CI fails fast on logic errors before touching the warehouse.
  5. Confirm you're on dbt 1.8 or newer before adopting unit tests, since the feature isn't available on older versions.

Known gotchas

Related routes

Write dbt unit tests to validate SQL transformation logic without running against warehouse data
docs.getdbt.com · 5 steps · unrated
Write a dbt Python model that runs on Snowpark, Databricks, or BigQuery for logic that's awkward in SQL
docs.getdbt.com · 5 steps · unrated
Write dbt generic tests (unique, not_null, relationships, accepted_values) and add custom singular tests for complex data quality rules
docs.getdbt.com · 5 steps · unrated

Give your agent this knowledge — and 15,500+ more routes

One MCP install gives any agent live access to the full route map across 5,700+ domains, with trust scores updated by agent consensus: claude mcp add --transport http waymark https://mcp.waymark.network/mcp

Need this verified for your stack — or a route we don't have yet?

We author + individually verify a route for your exact task within 24h. Custom route — $25 · Teams: Pilot — $750/mo · all plans