Bird
Raised Fist0
dbtdata~20 mins

Running tests with dbt test - Practice Problems & Coding Challenges

Choose your learning style10 modes available

Start learning this pattern below

Jump into concepts and practice - no test required

or
Recommended
Test this pattern10 questions across easy, medium, and hard to know if this pattern is strong
Challenge - 5 Problems
🎖️
dbt Test Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2:00remaining
Output of a dbt test run with a failing test
What is the output shown when you run dbt test and one of the tests fails due to a uniqueness violation?
dbt
dbt test
ANo tests found to run in the project.
BTest failed: uniqueness test on column 'user_id' in model 'orders' failed with 3 duplicate rows found.
CSyntaxError: invalid syntax in dbt test command.
DAll tests passed successfully with no errors.
Attempts:
2 left
💡 Hint
Think about what dbt reports when a uniqueness test fails.
🧠 Conceptual
intermediate
1:30remaining
Purpose of dbt test command
What is the main purpose of running dbt test in a dbt project?
ATo run data quality checks defined as tests on models and sources.
BTo generate documentation for the dbt project.
CTo deploy the dbt project to production environment.
DTo compile SQL models into tables and views.
Attempts:
2 left
💡 Hint
Think about what tests in dbt are used for.
data_output
advanced
2:00remaining
Result of a custom test returning rows
You define a custom test in dbt that returns rows where order_amount is negative. What does dbt test output if 5 rows violate this condition?
dbt
select * from {{ ref('orders') }} where order_amount < 0
ATest passed: no rows returned.
BRuntime error: invalid SQL syntax.
CTest skipped: no test defined.
DTest failed: 5 rows returned violating the condition.
Attempts:
2 left
💡 Hint
Custom tests fail when they return any rows.
🔧 Debug
advanced
2:00remaining
Error when running dbt test with missing test file
You run dbt test but get an error: Compilation Error: Could not find test file 'not_null_user_id.sql'. What is the cause?
AThe model 'user_id' does not exist in the project.
BThe database connection is not configured properly.
CThe test file is missing or not placed in the correct tests directory.
DThe dbt version is outdated and does not support tests.
Attempts:
2 left
💡 Hint
Check where dbt expects test files to be located.
🚀 Application
expert
3:00remaining
Interpreting dbt test summary output
After running dbt test, you see this summary:

PASS 1/3 tests
FAIL 2/3 tests
- test_not_null on model customers
- test_unique on model orders


What should you do next?
AInvestigate the failing tests to understand data quality issues and fix them.
BIgnore the failures since one test passed.
CDelete the failing tests to avoid errors in future runs.
DRun <code>dbt run</code> to overwrite the data and fix tests automatically.
Attempts:
2 left
💡 Hint
Failing tests indicate data problems that need attention.

Practice

(1/5)
1. What is the main purpose of running dbt test in a dbt project?
easy
A. To deploy the dbt project to production
B. To build new data models from raw data
C. To check data quality and find errors in your data models
D. To generate documentation for your data models

Solution

  1. Step 1: Understand the role of dbt test

    dbt test runs tests defined in your project to check data quality and catch errors.
  2. Step 2: Differentiate from other dbt commands

    Building models is done with dbt run, deployment is outside dbt test, and documentation is generated with dbt docs.
  3. Final Answer:

    To check data quality and find errors in your data models -> Option C
  4. Quick Check:

    dbt test = data quality checks [OK]
Hint: Remember: test = check data quality, run = build models [OK]
Common Mistakes:
  • Confusing dbt test with dbt run
  • Thinking dbt test deploys models
  • Assuming dbt test generates docs
2. Which of the following is the correct command to run tests only on a specific model named customers?
easy
A. dbt test --select customers
B. dbt run --models customers
C. dbt test --models customers
D. dbt test --only customers

Solution

  1. Step 1: Identify the correct flag for running tests on specific models

    The flag --select is used with dbt test to specify which models to test.
  2. Step 2: Check other options for correctness

    dbt run builds models, not tests. --models is not a valid flag for dbt test. --only is not a valid flag.
  3. Final Answer:

    dbt test --select customers -> Option A
  4. Quick Check:

    Use --select to target tests [OK]
Hint: Use --select flag to run tests on specific models [OK]
Common Mistakes:
  • Using dbt run instead of dbt test
  • Using invalid flags like --models or --only
  • Confusing --select with other flags
3. Given this schema.yml test definition:
models:
  - name: orders
    tests:
      - unique:
          column_name: order_id
      - not_null:
          column_name: order_date

What will dbt test check for the orders model?
medium
A. It checks that order_id is unique and order_date has no null values
B. It checks that order_id has no null values and order_date is unique
C. It checks that both order_id and order_date are unique
D. It checks that both order_id and order_date have no null values

Solution

  1. Step 1: Read the test types for each column

    The test unique applies to order_id, ensuring no duplicates. The test not_null applies to order_date, ensuring no missing values.
  2. Step 2: Match tests to their meaning

    unique means no duplicates; not_null means no nulls. So the checks are: order_id is unique and order_date has no null values.
  3. Final Answer:

    It checks that order_id is unique and order_date has no null values -> Option A
  4. Quick Check:

    unique = no duplicates, not_null = no nulls [OK]
Hint: unique = no duplicates, not_null = no nulls [OK]
Common Mistakes:
  • Mixing up unique and not_null tests
  • Assuming both columns have the same test
  • Ignoring the column_name key in test definitions
4. You run dbt test but get an error: Compilation Error: Could not find test 'uniquee'. What is the likely cause?
medium
A. The test passed with no errors
B. The model name is incorrect
C. The database connection is missing
D. A typo in the test name in schema.yml

Solution

  1. Step 1: Analyze the error message

    The error says it cannot find test 'uniquee', which looks like a misspelled test name.
  2. Step 2: Identify common causes of compilation errors

    Typos in test names in schema.yml cause dbt to fail to find the test. Model name or connection errors produce different messages.
  3. Final Answer:

    A typo in the test name in schema.yml -> Option D
  4. Quick Check:

    Compilation errors often mean typos [OK]
Hint: Check spelling of test names in schema.yml [OK]
Common Mistakes:
  • Ignoring typo errors and rerunning blindly
  • Assuming connection issues cause compilation errors
  • Confusing model name errors with test name errors
5. You want to ensure that the email column in your users model is unique and not null. You also want to run tests only on this model. Which schema.yml snippet and command combination is correct?
hard
A.
models:
  - name: users
    tests:
      - unique
      - not_null

Command: dbt test --models users
B.
models:
  - name: users
    columns:
      - name: email
        tests:
          - unique
          - not_null

Command: dbt test --select users
C.
models:
  - name: users
    columns:
      - name: email
        tests:
          - unique
          - not_null

Command: dbt run --models users
D.
models:
  - name: users
    tests:
      - unique
      - not_null

Command: dbt test --select users

Solution

  1. Step 1: Identify correct test syntax in schema.yml

    Tests on columns are defined under columns with name and tests list.
    models:
      - name: users
        columns:
          - name: email
            tests:
              - unique
              - not_null

    Command: dbt test --select users shows the correct format.
  2. Step 2: Choose the correct command to run tests on the users model

    dbt test --select users runs tests only on the users model.
    models:
      - name: users
        columns:
          - name: email
            tests:
              - unique
              - not_null

    Command: dbt test --select users uses this command correctly.
  3. Final Answer:

    Option B with column-level tests and dbt test --select users -> Option B
  4. Quick Check:

    Column tests + --select flag = correct [OK]
Hint: Define tests under columns, run with --select flag [OK]
Common Mistakes:
  • Defining tests directly under model without column_name (invalid syntax)
  • Using dbt run instead of dbt test
  • Using incorrect flags like --models