SpinTheMic
Pro

dbt · Beginner

What are the built-in generic tests in dbt?

By Anurag Pandey, Lead Data Engineer ·

The short answer

dbt ships four generic data tests: unique, not_null, accepted_values and relationships. Each one compiles to a query that returns failing rows; the test passes when it returns none.

Practice this out loud

Opens this question on SpinTheMic. Start without signing up; sign in free for an AI report card.

Say it like this

About 50 seconds out loud. Use it as a model, then put it in your own words.

dbt comes with four generic tests that I add in a model's YAML file. unique checks a column has no duplicates, which I use on primary keys. not_null checks for missing values. accepted_values checks a column only contains a list of allowed values, like order status. And relationships checks referential integrity, that every customer_id in orders exists in customers. Under the hood, each test is a select query that returns the rows breaking the rule, and the test passes when that query returns zero rows. I can set severity to warn instead of error, add thresholds, and store failures in a table to debug them. When the built-in ones aren't enough, I write singular tests or use a package like dbt-utils.

What interviewers look for

  • You name all four built-in generic tests with a use for each.
  • You know a test passes when its query returns zero rows.
  • You mention severity or storing failures, which shows production use.

Common mistakes

  • Calling them unit tests. Data tests check data; dbt unit tests check model logic.
  • Testing every column the same way, which creates noise people ignore.
  • Not knowing how to run only tests: dbt test or dbt build.

Follow-up questions to expect

  1. 1What is the difference between a generic and a singular test?
  2. 2How would you stop a noisy test from failing the whole build?
  3. 3How do dbt unit tests differ from data tests?
Practice this out loud

Opens this question on SpinTheMic. Start without signing up; sign in free for an AI report card.

Checked against

All interview question guides