Running tests with dbt test helps you check your data for mistakes or problems automatically. It makes sure your data is clean and reliable.
0
0
Running tests with dbt test
Introduction
After adding new data models to check if the data meets your rules.
Before sharing reports to ensure data quality.
When fixing data issues to confirm the problem is solved.
Regularly in your data pipeline to catch errors early.
Syntax
dbt
dbt test [--select <models>] [--exclude <models>] [--store-failures] [--data] [--schema]
dbt test runs tests defined in your project on your data models.
You can select specific models to test or exclude some using flags.
Examples
Runs all tests defined in your dbt project.
dbt
dbt test
Runs tests only on the
customers model.dbt
dbt test --select customers
Runs tests on all models except
orders.dbt
dbt test --exclude orders
Runs tests and saves any failing rows to a table for review.
dbt
dbt test --store-failures
Sample Program
This example shows how to define simple tests to check that the email column in the customers model is never empty and has unique values. Then, running dbt test --select customers checks these rules.
dbt
1. Define a test in your model's schema.yml file: version: 2 models: - name: customers columns: - name: email tests: - not_null - unique 2. Run the test in terminal: $ dbt test --select customers
OutputSuccess
Important Notes
Tests can be schema tests (check structure like uniqueness) or data tests (custom SQL queries).
Use --store-failures to save failing rows for easier debugging.
Running tests regularly helps keep your data trustworthy.
Summary
dbt test runs checks on your data models to find errors.
You can run tests on all or specific models using flags.
Defining tests in schema.yml files helps automate data quality checks.