dbt Testing and Documentation
5 min read Quiz at the end
dbt schema.yml defines unique, not_null, relationships, and accepted_values tests — run dbt test in CI.
dbt Testing and Documentation
# schema.yml -- define tests and documentation
version: 2
models:
- name: fct_orders
description: One row per completed order
columns:
- name: order_id
description: Unique order identifier
tests:
- unique
- not_null
- name: customer_id
tests:
- not_null
- relationships:
to: ref('dim_customers')
field: customer_id
- name: order_status
tests:
- accepted_values:
values: ['COMPLETED','PENDING','CANCELLED','REFUNDED']
- name: order_amount_usd
tests:
- not_null
- dbt_expectations.expect_column_values_to_be_between:
min_value: 0
max_value: 100000
# Run tests
dbt test # all tests
dbt test --select fct_orders # specific model
dbt test --severity warn # warn not fail
# Generate and serve docs
dbt docs generate
dbt docs serve # http://localhost:8080
# Lineage graph shows data flow through all models