How to Use dbt Tests

Last updated July 25, 2026 · By the SaturnSQL team

Attach generic data tests to columns in a schema.yml file, then run dbt test. dbt ships four built-in tests: unique, not_null, accepted_values, and relationships. A test fails when its query returns any rows.

# models/schema.yml
models:
  - name: fct_orders
    columns:
      - name: order_id
        data_tests:
          - unique
          - not_null
      - name: status
        data_tests:
          - accepted_values:
              values: ['placed', 'shipped', 'returned']
      - name: customer_id
        data_tests:
          - relationships:
              to: ref('dim_customers')
              field: customer_id

Running tests

dbt test
dbt test --select fct_orders

Since dbt 1.8 the YAML key is data_tests; the older tests: key still works. Packages like dbt-utils add many more generic tests on top of the built-in four.

Run this in SaturnSQL

SaturnSQL is a browser-based SQL editor for teams: shared query library, schema-aware autocomplete, and scheduled exports to Google Sheets and Slack.

Try it free

Related dbt guides

© 2026 Panda Capital Oy Ab. All rights reserved.