Skip to content
BENIBIX Learn

dbt Test

Data⚙️ ProcessingData Transformation

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

A dbt test is a check that dbt runs on the data in a model, a source or a snapshot. Each test is a SQL query that looks for rows that break a rule. If the query finds no rows, the test passes. dbt comes with four ready-made tests: unique, not_null, accepted_values and relationships. You add them to a column in a YAML file, then run dbt test.

Example code

yaml
models:
  - name: orders
    columns:
      - name: order_id
        data_tests:
          - unique
          - not_null
Two ready-made tests on one column. dbt test runs them both.
Tests sit beside the model they check and count the rows that break a rule.

Common mistake

Testing only the final tables. A problem is easier to find at the source, where it first gets in.

Key takeaways

  1. 1
    A query for bad rows. Zero rows found means a pass.
  2. 2
    Four built in. unique, not_null, accepted_values, relationships.
  3. 3
    Run every time. Test after each build, not now and then.