English · IndiaLog in
Rackwave Technologies
Request quote Free consultation
DataUpdated 26 Nov 2026

dbt Tests: Data Quality Checks for Every Model

dbt tests: generic, singular and unit tests, freshness, severity and CI.

Written by Rohan Verma
  • Published25 Nov 2026
  • Read time6 min
  • Length1,268 words
Share this guide

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.

dbt tests diagram
Figure 1. dbt tests: source, staging, mart and how they relate.

Types of dbt tests

TypeWhat it checksExample
Generic: uniqueNo duplicate values in a columnPrimary keys
Generic: not nullNo missing valuesRequired identifiers
Generic: accepted valuesValues are in an allowed listStatus codes
Generic: relationshipsForeign keys match a parent tableOrders refer to real customers
Singular testCustom SQL that returns failing rowsRevenue equals payments total
Unit testLogic gives expected output for fixed inputComplex case statements
Source freshnessRaw data arrived recentlyOrders loaded within six hours

Packages add many more, such as range, regular expression and row count checks.

Where to place tests

LayerRecommended testsReason
SourcesFreshness, not null on keysCatch upstream problems early
StagingUnique and not null on keys, accepted valuesConfirm clean inputs
IntermediateRelationships and row count expectationsCatch join errors
MartsKeys, relationships, business rules and totalsProtect what users see

Test early to find causes and late to protect consumers. See dbt models and sources and seeds.

Testing at a glance summary
Figure 2. Testing at a glance: generic, singular, freshness at a glance.

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

  1. Define the rules. Agree with business owners what must always be true.
  2. Write tests with models. Add tests in the same pull request as the model.
  3. Run in CI. Build changed models and run their tests before merge.
  4. Run in production. Execute tests on every scheduled build.
  5. Alert and triage. Route failures to the model owner with context.
  6. 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.

Read getting started with dbt, data lineage, data governance and master data management for related topics.

Testing checklist

ItemDone when
KeysUnique and not null on every model
RelationshipsFacts match dimensions
Business rulesCritical totals reconciled
CITests run per pull request
AlertsFailures reach owners
NoiseWarnings 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

TermMeaning
Generic testReusable configured test
Singular testCustom SQL assertion
Unit testLogic check with fixed input
FreshnessCheck that data arrived recently
SeverityWhether 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.

Was this guide helpful?Your answer helps us decide what to improve. It is not linked to you.

#dbt tests#dbt data quality tests#dbt generic tests#dbt singular tests#dbt source freshness

About the author

Rohan Verma

Data Platforms Consultant

Rohan works across CDP, data warehouse, and analytics platform implementations, helping clients figure out which data infrastructure actually fits their scale rather than defaulting to whatever's currently trending.

Data Platforms & Technical Architecture

Ready to put AI and data to work?

Book a free consultation and leave with a plan, not a pitch.

Get a free consultationRequest quote