Skip to content

10. Write the Tests for an Orders Model

Difficulty: Easy · Topic: Data tests

The orders model (order_id, customer_id, status, amount) feeds the revenue dashboard. Write models/schema.yml with data tests that enforce what the business promises:

Your tests are run on several datasets. On a clean dataset every test must pass (a test that fails on good data stops the pipeline for nothing). On a broken dataset at least one test must fail. You see two datasets; the hidden ones break the rules in other ways.

Your schema.yml tests run on 7 datasets, including hidden ones: clean datasets must pass every test, broken ones must make a test fail.

Clean data (clean)

{{ ref('orders') }}

order_idcustomer_idstatusamount
110placed25
211shipped40.5
310completed12
412placed99.99

A status typo (broken)

A new app version writes "shiped".

{{ ref('orders') }}

order_idcustomer_idstatusamount
110placed25
211shiped40.5
310completed12

Hints

Hint 1Column tests go under columns:, each with a name and a list of data_tests (or tests): - unique, - not_null.
Hint 2accepted_values takes the list of values: - accepted_values: {arguments: {values: [placed, shipped, completed, returned]}} (older projects put values directly under the test name; both work).
Hint 3Check what accepted_values does with a null status: null not in (...) is not true, so the row is not reported.

Learn the concepts

More dbt problems

All dbt problems