Introduction
Testing helps catch mistakes in data early. It makes sure data is correct and reliable for decisions.
Jump into concepts and practice - no test required
Testing helps catch mistakes in data early. It makes sure data is correct and reliable for decisions.
version: 2 models: - name: your_model_name tests: - unique: column_name: id - not_null: column_name: id - accepted_values: column_name: status values: ['active', 'inactive']
Tests are defined in YAML files inside your dbt project.
Common tests include unique, not_null, and accepted_values.
customer_id has no duplicates.version: 2
models:
- name: customers
tests:
- unique:
column_name: customer_idorder_date is never empty.version: 2
models:
- name: orders
tests:
- not_null:
column_name: order_datecategory only contains allowed values.version: 2 models: - name: products tests: - accepted_values: column_name: category values: ['electronics', 'furniture', 'clothing']
This example shows a dbt test setup for a sales model. It checks that sale_id is unique, sale_date is not empty, and region only has allowed values.
version: 2 models: - name: sales tests: - unique: column_name: sale_id - not_null: column_name: sale_date - accepted_values: column_name: region values: ['north', 'south', 'east', 'west']
Tests help find data problems before they affect reports.
Failing tests mean you should fix data or logic in your models.
Regular testing builds trust in your data.
Testing checks data correctness automatically.
It catches errors early to avoid bad decisions.
dbt makes it easy to add and run data tests.
{"failures": 3, "total_tests": 5}tests: - not_null: id - unique: id