⚙️dbt Test
Also known as dbt Data Test, dbt Tests, data_tests
A check that dbt runs on a table. It passes when no row breaks the rule.
Think of it like
It is like a spell checker that runs after you type. It points at each word that breaks a rule.
Example
Emma adds unique and not_null to the order_id column. One night a load repeats 14 orders. The unique test fails before anyone sees a report.
Why it matters
Bad data is caught where it starts. A manager does not find an odd number weeks later.
Definition
Example code
yaml
models:
- name: orders
columns:
- name: order_id
data_tests:
- unique
- not_nullCommon mistake
Key takeaways
- 1A query for bad rows. Zero rows found means a pass.
- 2Four built in. unique, not_null, accepted_values, relationships.
- 3Run every time. Test after each build, not now and then.