The Mental Model
Data tests are executable assumptions. They do not prove data is perfect, but they catch the breakages you know would make the model unsafe.
A test is a smoke alarm. It does not stop every fire, but it tells you when a known danger is happening.
Dataset reference: ecommerce tables and grain assumptions.
Turn a key assumption into a failing test
A dimension containing customer IDs 7, 7, and NULL should fail both uniqueness and non-null checks. This dbt model properties file expresses those assumptions:
version: 2
models:
- name: dim_customers
columns:
- name: customer_id
data_tests:
- unique
- not_null
Run dbt test --select dim_customers after building the model. A test failure means the assumed key contract is broken; it does not prove which upstream source caused it. Add a relationship test from orders to customers separately if referential integrity is required. See dbt data tests.
Acceptance check: deliberately duplicate a key in a development fixture and confirm the test fails before relying on it as a release gate.
Interactive Check
Question: Which test should protect customer_id in dim_customers?
Reveal the answer
Use unique and not_null. A customer dimension needs exactly one non-null row per customer_id.
Practice: Add the First Tests
Add basic dbt-style tests to fct_orders and dim_customers.
Use the guided lab below to record your result, assumptions, and the check that would catch an incorrect result.