dbt test runs assertions defined for dbt resources and reports whether transformed data meets expected quality and consistency rules. Define tests beside models in schema.yml, then run the command after building the pipeline. section 8.3.4
A practical validation workflow:
- Assert required identifiers are not NULL. section 8.3.4
- Restrict categorical fields with accepted_values, such as Grass, Hard, Clay, and Carpet. section 8.3.4 section 8.3.5
- Extend built-in checks with dbt_expectations for types and date ranges. section 8.3.4
- Inspect failing tests, update the schema or transformation, rerun dbt run, and validate again. section 8.3.5
Validate an ATP matches model
Put not_null and accepted_values tests for tourney_id, winner_id, loser_id, and surface in models/atp/schema.yml. Run dbt test; failures identify invalid values, missing surfaces, or out-of-range dates. section 8.3.4 section 8.3.5
Listing 8.10 A dbt schema asserting various qualities of our dataset
version: 2
models:
- name: matches
description: "ATP tennis matches schema"
columns:
- name: tourney_id
description: "The ID of the tournament."
tests:
- not_null
- name: winner_id
description: "The ID of the winning player."
tests:
- not_null
- name: loser_id
description: "The ID of the losing player."
tests:
- not_null
- name: surface
description: "The surface of the court."
tests:
- not_null
- accepted_values:
values: ['Grass', 'Hard', 'Clay']
Shows the YAML structure for attaching column-level assertions to a dbt model. section 8.3.4
