Skip to content

Turning an assumption about a model or source into a test

dbt tests validate assumptions about your data by running SQL queries that return failing rows. dbt ships with four built-in generic tests (unique, not_null, accepted_values, relationships) that can be applied to models, sources, seeds, and snapshots via YAML properties files. Tests are essential for catching data quality issues before they propagate downstream.

1 · Learn the must-know

  • Generic (schema) tests are defined in YAML under a 'tests' key on columns or models/sources, while singular tests are standalone .sql files in the tests/ directory that must return zero rows to pass.
  • The 'unique' and 'not_null' tests check a single column; 'accepted_values' checks that column values fall within a specified list; 'relationships' checks referential integrity against a column in another model or source.
  • Tests can be configured with severity: warn or error (default error), and error_if/warn_if thresholds can be set to control when a test fails vs. warns based on row count.
  • Running 'dbt test' executes all tests; you can scope execution using selectors like '--select model_name' or 'source:*' to test only sources.
  • Tests defined on sources allow you to validate assumptions about raw data freshness and structure before it enters your transformation pipeline, catching upstream issues early.
  • Custom generic tests can be created as macros (prefixed test__) in the macros/ or tests/generic/ directory and reused across multiple models with parameters, similar to built-in tests.

2 · Check your understanding

Check this objectiveFree · always available

A source freshness block is defined as follows: sources: - name: jaffle_shop loaded_at_field: _loaded_at freshness: warn_after: {count: 12, period: hour} error_after: {count: 24, period: hour} tables: - name: raw_orders The most recent row in raw_orders has a _loaded_at value 30 hours old. What is the result of running dbt source freshness?

Your objective map0 tried · 0 answered correctly · 31 untouched

What you have tried across dbt Analytics Engineering's objectives, not a readiness score.

Developing and optimizing dbt models45.16% of the exam*0 of 14 tried
Managing dbt models governance9.68% of the exam*0 of 3 tried
Debugging data modeling errors16.13% of the exam*0 of 5 tried
Troubleshooting and optimizing dbt pipelines6.45% of the exam*0 of 2 tried
Implementing dbt tests9.68% of the exam*0 of 3 tried
Implementing and maintaining external dependencies6.45% of the exam*0 of 2 tried
Leveraging the dbt state6.45% of the exam*0 of 2 tried

* Our estimate. dbt Labs publishes no section weights.

3 · Keep going