What are dbt tests? dbt tests are assertions about your data and your models that run automatically as part of a build. Generic tests such as unique, not null, accepted values and relationships check common rules with a line of configuration, while singular tests are custom SQL queries that return rows when something is wrong. Tests turn data quality from an occasional manual check into a repeatable control that runs on every change and every scheduled run. This guide explains the types of tests, where to place them, how to set severity and thresholds, how to test sources and complex logic, how to run tests in continuous integration, how to handle failures and the mistakes that leave projects either untested or buried in noise. Details vary by version, so confirm in current dbt documentation.
Short answer: Add unique and not-null tests to every primary key, relationship tests between facts and dimensions, accepted-value tests to categorical columns and custom tests to critical metrics. Run them on every build, store failures and act on them.
Why test data transformations
Pipelines fail quietly. A source changes a column, a join duplicates rows or a filter drops a region, and dashboards keep updating with wrong numbers. Tests catch these problems close to where they occur, before decisions are made on bad data. They also document expectations and make refactoring safer. See data quality and data observability.

Types of dbt tests
| Type | What it checks | Example |
|---|---|---|
| Generic: unique | No duplicate values in a column | Primary keys |
| Generic: not null | No missing values | Required identifiers |
| Generic: accepted values | Values are in an allowed list | Status codes |
| Generic: relationships | Foreign keys match a parent table | Orders refer to real customers |
| Singular test | Custom SQL that returns failing rows | Revenue equals payments total |
| Unit test | Logic gives expected output for fixed input | Complex case statements |
| Source freshness | Raw data arrived recently | Orders loaded within six hours |
Packages add many more, such as range, regular expression and row count checks.
Where to place tests
| Layer | Recommended tests | Reason |
|---|---|---|
| Sources | Freshness, not null on keys | Catch upstream problems early |
| Staging | Unique and not null on keys, accepted values | Confirm clean inputs |
| Intermediate | Relationships and row count expectations | Catch join errors |
| Marts | Keys, relationships, business rules and totals | Protect what users see |
Test early to find causes and late to protect consumers. See dbt models and sources and seeds.

Setting severity and thresholds
- Use error severity for checks that must block downstream models.
- Use warn severity for softer expectations that need attention but not a stop.
- Set thresholds, such as allowing a small number of failures, where perfection is unrealistic.
- Tag tests as critical or advisory so alerts reach the right people.
- Review warnings regularly, or they become permanent noise.
- Store failing rows in a table so owners can investigate.
A testing workflow
- Define the rules. Agree with business owners what must always be true.
- Write tests with models. Add tests in the same pull request as the model.
- Run in CI. Build changed models and run their tests before merge.
- Run in production. Execute tests on every scheduled build.
- Alert and triage. Route failures to the model owner with context.
- Fix and prevent. Fix the cause and add a test so it cannot recur.
Testing complex logic
Business rules such as revenue recognition or customer status are easy to get wrong. Write singular tests that compare model outputs with known totals, for example that daily revenue equals the sum of payments. Use unit tests with small fixed inputs and expected results for tricky case statements and window functions, so changes can be checked without needing production data.
- Reconcile totals with source systems.
- Use fixed fixtures for tricky logic.
- Test edge cases such as nulls and ties.
- Keep custom tests readable and documented.
Storing and triaging test failures
Knowing that a test failed is only half the job. Configure dbt to store failing rows in a dedicated schema, so an owner can see exactly which records broke the rule. Add a short description to each test explaining the business meaning and the likely cause, and link to a runbook for common fixes.
Triage should be routine. Route alerts to the team that owns the model, classify failures as data, logic or upstream problems and record the resolution. Over time this history shows which sources and models are fragile and where investment in quality will pay off most.
- Store failing rows for investigation.
- Describe the business meaning of each test.
- Route alerts to model owners.
- Review failure history monthly.
Packages and extending tests
Community packages provide ready-made tests for ranges, patterns, row counts, recency and distribution checks, and tools that profile models and suggest where tests are missing. Review packages before adopting them, pin their versions and prefer a small set that your team understands. When a custom rule is used often, wrap it in a reusable generic test so that other models can adopt it with one line of configuration.
Common mistakes
- Testing nothing on the keys of important models.
- Adding hundreds of low-value tests that create noise.
- Ignoring warnings until they hide real failures.
- Running tests only in production, so errors reach users first.
- No owner for failing tests.
- Testing only formats and never business rules.
A worked example
An analytics team added unique and not-null tests to all keys, relationship tests between orders and customers and a reconciliation test that compared daily revenue with the payment system. Failures stored their rows and notified the model owner.
Within a month, tests caught a duplicate-order bug from a source change before the dashboard refreshed, and the fix was a small change. The example is illustrative.
Best practices and support
- Start with keys and relationships, then add business rules.
- Fail fast in CI.
- Track test failure trends.
- Review and retire low-value tests.
Our data governance service and data analytics service build testing and quality controls for dbt projects.
Related guides
Read getting started with dbt, data lineage, data governance and master data management for related topics.
Testing checklist
| Item | Done when |
|---|---|
| Keys | Unique and not null on every model |
| Relationships | Facts match dimensions |
| Business rules | Critical totals reconciled |
| CI | Tests run per pull request |
| Alerts | Failures reach owners |
| Noise | Warnings reviewed monthly |
Source freshness and volume checks
Many data problems start upstream: a feed stops, a file arrives late or volume drops by half. Configure freshness checks on sources, with warn and error thresholds that match how often data should arrive, and add row count and volume checks for critical tables. Running these before transformations avoids wasting compute and stops bad data early.
- Set freshness per source.
- Check expected volume ranges.
- Run source checks before models.
- Alert the source owner directly.
Measuring test coverage and value
Track the share of models with key tests, the number of failures caught before release and the time to fix. Use these measures to direct effort: add tests where failures hurt most, and retire tests that never fail and protect nothing important. Coverage is a means, not a goal, and quality of tests matters more than their number.
Key takeaways
- Tests are assertions that run on every build.
- Cover keys, relationships and business rules.
- Use severity and thresholds wisely.
- Run tests in CI and production.
- Assign owners to failures.
Quick glossary
| Term | Meaning |
|---|---|
| Generic test | Reusable configured test |
| Singular test | Custom SQL assertion |
| Unit test | Logic check with fixed input |
| Freshness | Check that data arrived recently |
| Severity | Whether a failure warns or blocks |
Read next: BigQuery vs Snowflake: Which Cloud Data Platform? · BigQuery Streaming Inserts: Real-Time Ingestion Guide · BigQuery Access Control: IAM, Policy Tags and Row Security
Frequently asked questions
What are dbt tests?
Assertions about data that run during a build and fail when a rule is broken.
What are generic tests?
Reusable tests such as unique, not null, accepted values and relationships, added with configuration.
What are singular tests?
Custom SQL queries that return rows when a rule is violated.
Can dbt test source freshness?
Yes. Freshness checks confirm that raw data arrived within an expected time.
What is the difference between warn and error?
Error blocks downstream work, while warn reports a problem without stopping the run.
Should I run tests in CI?
Yes. Run tests for changed models on every pull request to catch problems before merge.
How do I test business logic?
Use singular tests that reconcile totals and unit tests with fixed inputs and expected outputs.
How many tests are enough?
Cover keys, relationships and critical rules first, then add tests where failures cause real harm.
