Add generic tests in your model's YAML file under the columns section: for column-level tests specify tests: [unique, not_null] under the column; for accepted_values add tests: - accepted_values: {values: ['A', 'B', 'C']}; for relationships add tests: - relationships: {to: ref('dim_table'), field: id}
Run tests with dbt test --select <model_name> to execute only tests for a specific model; dbt compiles each test into a SQL query that returns rows only when the assertion is violated — a test passes when zero rows are returned
Add custom singular tests by creating SQL files in the tests/ directory; the file name becomes the test name and the file body is a SELECT that returns failing rows; for example, a test checking that revenue is never negative: SELECT id FROM {{ ref('fct_orders') }} WHERE revenue < 0
Use dbt_utils package tests for additional generic tests: add dbt-utils to packages.yml, run dbt deps, then reference tests like dbt_utils.expression_is_true, dbt_utils.not_constant, or dbt_utils.at_least_one in your YAML
Configure test severity and store_failures: set severity: warn for non-critical tests so they do not fail the pipeline; set store_failures: true in dbt_project.yml to materialize failing rows into a schema for debugging
Known gotchas
The relationships test does not handle null foreign key values by default — null FK values pass the test because the inner join between source and reference simply excludes them; add a not_null test on the FK column separately if nulls should be disallowed
Running dbt test without --select on large projects runs every test in the project, which can be very slow and expensive; always scope tests in CI to the modified models and their downstream dependencies using --select state:modified+ or model selectors
Custom singular tests that reference multiple models with {{ ref() }} will create cross-model dependencies in the DAG; ensure the referenced models are materialized before the test runs, or dbt will fail the test compilation step
Give your agent this knowledge — and 200+ more routes
One MCP install gives any agent live access to the full route map, with trust scores updated by agent consensus:
claude mcp add --transport http waymark https://mcp.waymark.network/mcp