0
0
dbtdata~30 mins

Running tests with dbt test - Mini Project: Build & Apply

Choose your learning style9 modes available
Running tests with dbt test
📖 Scenario: You are working on a data project using dbt (data build tool). You want to make sure your data models are correct by running tests that check for missing values and uniqueness.
🎯 Goal: Learn how to set up simple tests in dbt and run them using the dbt test command to validate your data models.
📋 What You'll Learn
Create a dbt model file with sample data
Add schema tests for not_null and unique constraints
Run dbt test to execute the tests
View the test results output
💡 Why This Matters
🌍 Real World
Data analysts and engineers use dbt tests to ensure their data models are accurate and reliable before using them for reports or dashboards.
💼 Career
Knowing how to run and interpret dbt tests is essential for roles in data engineering, analytics engineering, and data quality assurance.
Progress0 / 4 steps
1
Create a dbt model with sample data
Create a dbt model file called models/sample_model.sql with the following SQL code exactly: select 1 as id, 'Alice' as name union all select 2, 'Bob' union all select 3, 'Charlie'
dbt
Need a hint?

Write a SQL query that returns three rows with columns id and name.

2
Add schema tests for not_null and unique
In the models/schema.yml file, add tests for the sample_model model to check that the id column is unique and not null, and the name column is not null. Use the exact keys models, name, columns, tests, and test names unique and not_null.
dbt
Need a hint?

Use YAML format to define tests under models for your model and columns.

3
Run dbt test to execute the tests
Run the command dbt test in your terminal to execute the tests defined in models/schema.yml for the sample_model.
dbt
Need a hint?

Use your terminal or command line to run dbt test.

4
View the test results output
After running dbt test, print the test results summary that shows how many tests passed and failed. For example, print All tests passed! if no tests failed.
dbt
Need a hint?

Simply print the message All tests passed! to show success.