Can be applied to Models as well as Sources.

There are two types of dbt tests:

Singular tests

It is represented as a .sql file located in the tests/ folder. This test references a table using ref or the source macro.

Generic tests

Builtin tests include:

  • unique
  • not_null
  • accepted_values
  • relationships

Additional tests can be imported from 3rd party packages or written with your own custom generic test.

The tests ares specified in the .yml file of models and sources in the models/ folder.

Command

To run tests, use dbt test.

You can also select a subset of tests to run as follows:

  • dbt test --select test_type:generic
  • dbt test --select test_type:singular
  • dbt test --select one_specific_model

Tip

dbt build is a better command that interleaves both dbt run and dbt test, model-by-model. It’ll fail downstream materializations if a test fails.