Running dbt tests
You can write tests for your dbt models by following dbt’s documentation.
When a pipeline runs, each dbt model block will run and then each test associated with that dbt model will be ran.
For example, if you add a dbt block to your pipeline for a dbt model named
my_third_dbt_model
and a test file named test_my_third_dbt_model.sql
with
the following folder structure:
Then whenever your pipeline runs, the test in test_my_third_dbt_model.sql
will also be ran after the dbt run for the model my_third_dbt_model
is
complete.
Any errors in the dbt test will also fail the pipeline run. The output of the test will be logged and viewable when inspecting the pipeline’s run and logs.
Folder and file naming conventions
In your tests folder, you must mirror the path of the model you want to test.
For example, if your model is named my_third_dbt_model
and if its located
under the folder named example
, then your test file must be located here:
Note that the model file and test file have the same name (e.g.
my_third_dbt_model.sql
) and are nested under a folder with identical names
(e.g. example
).
Example
The content of the dbt model named my_third_dbt_model
is:
Failed test
The content of the test for my_third_dbt_model.sql
that will cause a test
failure is:
Here is the sample output of a failed test for the above files:
Successful test
The content of the test for my_third_dbt_model.sql
that will yield a passing
test is:
Here is the sample output of a successful test for the above files:
Was this page helpful?