dbt Fundamentals
Back to Building a Real dbt Project

Tests — Built-in and Custom

Generic tests in YAML, custom SQL tests, what to test for vs what to skip. FIND_VIDEO: search 'dbt tests unique not_null relationships' — recommended channel: dbt Labs. Aim for 10 min or under.

16 minutesVideo LessonPDF notes
🎯 Free Guest Mode: You are learning for free. Sign in to save your completion progress and quiz answers.
Loading progress...

Key moments

  1. Core Test Categories — Differentiate between declarative generic YAML tests and custom singular SQL tests.
  2. Configuring Data Sources — Define raw source schemas in YAML and update staging models to use the source macro.
  3. Creating Singular Tests — Author a custom SQL test checking for negative payment amounts using inverted failure logic.
  4. Applying Generic Tests — Add unique and not_null constraints to customer ID columns in schema YAML files.
  5. Accepted Values and Debugging — Configure accepted_values tests on status columns and debug failures using compiled SQL.
  6. Testing Data Sources — Extend declarative generic tests directly to raw source table configurations in YAML.
PDF notes

Frequently asked questions

Why did my singular test fail if the query returned expected data?

dbt tests fail whenever any rows are returned. Singular test queries must return zero rows to pass.

What are the four built-in generic tests in dbt?

The four built-in generic tests are unique, not_null, accepted_values, and relationships.

Where can I find the exact query executed by a failing generic test?

dbt prints the compiled SQL file path in the terminal, located inside the target/compiled/ directory.

Can I run tests on raw sources before executing downstream models?

Yes, you can target source tests specifically using the command dbt test -s source:source_name.

How was this lesson?

Your feedback helps us refine explanations and catch bugs.