0
0
dbtdata~5 mins

Why testing ensures data quality in dbt

Choose your learning style9 modes available
Introduction

Testing helps catch mistakes in data early. It makes sure data is correct and reliable for decisions.

When you want to check if new data matches expected rules
Before using data to create reports or dashboards
When combining data from different sources to ensure consistency
After changing data pipelines to confirm nothing broke
To monitor data quality regularly and catch errors fast
Syntax
dbt
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.

Examples
This test checks that customer_id has no duplicates.
dbt
version: 2
models:
  - name: customers
    tests:
      - unique:
          column_name: customer_id
This test ensures order_date is never empty.
dbt
version: 2
models:
  - name: orders
    tests:
      - not_null:
          column_name: order_date
This test confirms category only contains allowed values.
dbt
version: 2
models:
  - name: products
    tests:
      - accepted_values:
          column_name: category
          values: ['electronics', 'furniture', 'clothing']
Sample Program

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.

dbt
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']
OutputSuccess
Important Notes

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.

Summary

Testing checks data correctness automatically.

It catches errors early to avoid bad decisions.

dbt makes it easy to add and run data tests.