Introduction

In dbt, one of the most essential commands is dbt test. In this tutorial, we’ll dive into the dbt test command, exploring its syntax, functionality, and practical usage. This tutorial is also a valuable resource for those studying for the dbt Analytics Engineering Certification Exam.

Explanation of dbt test

The dbt test command is a core function in dbt that validates data models by executing predefined tests within a project. It ensures data quality by running two types of tests:

  • Generic tests defined in .yml files (for example uniquenot_null, and accepted_values).
  • Singular tests written in .sql files.

Running tests helps ensure that your data meets integrity constraints and predefined quality standards before being used in downstream processes.

Basic Syntax

The basic syntax for the dbt test command is the following:

dbt test

When you run this command in your terminal, dbt will test all models in your project by default. It will run the generic and singular tests defined for each model and report any failures.

Specific options

Specific options allow you to customize and control the dbt test command. Let's have a look at 9 different options to specify the dbt test command.

1) Test single model

To test a single model, use the --select flag followed by the model name:

dbt test --select model_name

2) Test multiple models

To test multiple models, use the --select flag followed by the model names:

dbt test --select model_name1 model_name2 model_name3

3) Exclude model

To exclude one or more models from being tested, use the --exclude flag followed by the model name(s):

dbt test --exclude model_name

4) Test models within a path

To test all models within a specific path, use the --select flag followed by the path to the models:

dbt test --select path/to/my/models

5) Run only singular tests

You can view this post with the tier: Academy Membership

Join academy now to read the post and get access to the full library of premium posts for academy members only.

Join Academy Already have an account? Sign In