liveBook · Manning

Dbt test

As explained in DuckDB in Action

The dbt test command runs the tests defined for dbt resources and reports their results.

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

How DuckDB in Action covers it

How deep it goes
Explains schema declarations, command output, package installation, and failure-driven fixes without detailing test internals.
Examples
Uses ATP tennis matches, column constraints, date-range assertions, failing test output, and grouped surface-value inspection.
What it assumes
Assumes a configured dbt project with models and schema.yml, while introducing assertions from basic built-ins to package extensions.
What you can do after
Diagnose data-quality failures and refine dbt schemas or SQL transformations until pipeline assertions pass.
How it connects
Connects data quality to dbt models, schema.yml, DuckDB, dbt_expectations, Parquet, and data transformation pipelines.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of DuckDB in Action. The section links point to the parts of the book it draws on.