Manifest Checks: Unit Tests#
Note
The below checks require manifest.json to be present.
Checks related to unit test coverage and formats.
Functions:
| Name | Description |
|---|---|
check_unit_test_coverage |
Set the minimum percentage of models that have a unit test. |
check_unit_test_expect_format |
Unit tests can only use the specified formats. |
check_unit_test_given_formats |
Unit tests can only use the specified formats. |
check_unit_test_coverage
#
Set the minimum percentage of models that have a unit test.
Rationale
Unit tests validate that a model's SQL logic produces the correct output for a given set of inputs, independently of live data. Tracking coverage across the project ensures that critical business logic is not left untested, which reduces the risk of silent regressions when models are refactored or when source data shapes change unexpectedly.
Warning
This check is only supported for dbt 1.8.0 and above.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
min_unit_test_coverage_pct
|
float
|
The minimum percentage of models that must have a unit test. |
100
|
Receives at execution time:
| Name | Type | Description |
|---|---|---|
models |
list[ModelNode]
|
List of ModelNode objects parsed from |
unit_tests |
list[UnitTests]
|
List of UnitTests objects parsed from |
Other Parameters (passed via config file):
| Name | Type | Description |
|---|---|---|
description |
str | None
|
Description of what the check does and why it is implemented. |
include |
str | None
|
Regex pattern to match the model path. Only model paths that match the pattern will be checked. |
severity |
Literal[error, warn] | None
|
Severity level of the check. Default: |
Example(s):
Source code in src/dbt_bouncer/checks/manifest/check_unit_tests.py
check_unit_test_expect_format
#
Unit tests can only use the specified formats.
Rationale
dbt unit tests support multiple expect formats — csv, dict, and sql — each with different trade-offs in readability, portability, and maintenance overhead. Restricting permitted formats enforces a project-wide standard that keeps unit tests consistent and readable, and avoids formats that may be harder for the team to maintain (e.g. raw SQL expectations that are difficult to diff).
Warning
This check is only supported for dbt 1.8.0 and above.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
permitted_formats
|
list[Literal[csv, dict, sql]] | None
|
A list of formats that are allowed to be used for |
['csv', 'dict', 'sql']
|
Receives at execution time:
| Name | Type | Description |
|---|---|---|
manifest_obj |
ManifestObject
|
The ManifestObject object parsed from |
unit_test |
UnitTests
|
The UnitTests object to check. |
Other Parameters (passed via config file):
| Name | Type | Description |
|---|---|---|
description |
str | None
|
Description of what the check does and why it is implemented. |
exclude |
str | None
|
Regex pattern to match the unit test path (i.e the .yml file where the unit test is configured). Unit test paths that match the pattern will not be checked. |
include |
str | None
|
Regex pattern to match the unit test path (i.e the .yml file where the unit test is configured). Only unit test paths that match the pattern will be checked. |
severity |
Literal[error, warn] | None
|
Severity level of the check. Default: |
Example(s):
Source code in src/dbt_bouncer/checks/manifest/check_unit_tests.py
check_unit_test_given_formats
#
Unit tests can only use the specified formats.
Rationale
The given section of a dbt unit test defines the mock input data for the test. Standardising the format across all given inputs (e.g. requiring csv for human-readable diffs in code review) keeps tests consistent and ensures that engineers reviewing test changes can quickly assess whether the input data is correct without needing to parse unfamiliar formats.
Warning
This check is only supported for dbt 1.8.0 and above.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
permitted_formats
|
list[Literal[csv, dict, sql]] | None
|
A list of formats that are allowed to be used for |
['csv', 'dict', 'sql']
|
Receives at execution time:
| Name | Type | Description |
|---|---|---|
manifest_obj |
ManifestObject
|
The ManifestObject object parsed from |
unit_test |
UnitTests
|
The UnitTests object to check. |
Other Parameters (passed via config file):
| Name | Type | Description |
|---|---|---|
description |
str | None
|
Description of what the check does and why it is implemented. |
exclude |
str | None
|
Regex pattern to match the unit test path (i.e the .yml file where the unit test is configured). Unit test paths that match the pattern will not be checked. |
include |
str | None
|
Regex pattern to match the unit test path (i.e the .yml file where the unit test is configured). Only unit test paths that match the pattern will be checked. |
severity |
Literal[error, warn] | None
|
Severity level of the check. Default: |
Example(s):