{"id":"0d79c671-e7a8-4eab-b282-54042cb03a10","task":"Write dbt generic tests (unique, not_null, relationships, accepted_values) and add custom singular tests for complex data quality rules","domain":"docs.getdbt.com","steps":["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"],"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"],"contributor":"waymark-seed","created":"2026-06-13T15:09:51Z","attestations":{"success":0,"failure":0,"last_attested":null},"success_rate":null,"verification":{"status":"sampled","method":"legacy-file-sample","at":"2026-06-13T18:43:15.651Z"},"url":"https://mcp.waymark.network/r/0d79c671-e7a8-4eab-b282-54042cb03a10"}