Skip to content

Commit

Permalink
add more info to overrides for unit testing (#4978)
Browse files Browse the repository at this point in the history
## What are you changing in this pull request and why?
<!---
Describe your changes and why you're making them. If related to an open 
issue or a pull request on dbt Core, then link to them here! 

To learn more about the writing conventions used in the dbt Labs docs,
see the [Content style
guide](https://github.com/dbt-labs/docs.getdbt.com/blob/current/contributing/content-style-guide.md).
-->

Add more docs / examples to overrides for unit testing - fast follow
from here #4889

## Checklist
<!--
Uncomment when publishing docs for a prerelease version of dbt:
- [ ] Add versioning components, as described in [Versioning
Docs](https://github.com/dbt-labs/docs.getdbt.com/blob/current/contributing/single-sourcing-content.md#versioning-entire-pages)
- [ ] Add a note to the prerelease version [Migration
Guide](https://github.com/dbt-labs/docs.getdbt.com/tree/current/website/docs/docs/dbt-versions/core-upgrade)
-->
- [ ] Review the [Content style
guide](https://github.com/dbt-labs/docs.getdbt.com/blob/current/contributing/content-style-guide.md)
so my content adheres to these guidelines.
- [ ] For [docs
versioning](https://github.com/dbt-labs/docs.getdbt.com/blob/current/contributing/single-sourcing-content.md#about-versioning),
review how to [version a whole
page](https://github.com/dbt-labs/docs.getdbt.com/blob/current/contributing/single-sourcing-content.md#adding-a-new-version)
and [version a block of
content](https://github.com/dbt-labs/docs.getdbt.com/blob/current/contributing/single-sourcing-content.md#versioning-blocks-of-content).
- [ ] Add a checklist item for anything that needs to happen before this
PR is merged, such as "needs technical review" or "change base branch."

Adding or removing pages (delete if not applicable):
- [ ] Add/remove page in `website/sidebars.js`
- [ ] Provide a unique filename for new pages
- [ ] Add an entry for deleted pages in `website/static/_redirects`
- [ ] Run link testing locally with `npm run build` to update the links
that point to deleted pages
  • Loading branch information
graciegoheen authored Feb 23, 2024
2 parents 9fcc45b + 35dc061 commit 42f7fd2
Showing 1 changed file with 54 additions and 1 deletion.
55 changes: 54 additions & 1 deletion website/docs/reference/resource-properties/unit-tests.md
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,60 @@ When `format: csv`, can either supply:

### Overrides

When configuring your unit test, you can override the output of macros, vars, or environment variables for a given unit test.
When configuring your unit test, you can override the output of [macros](/docs/build/jinja-macros#macros), [project variables](/docs/build/project-variables), or [environment variables](/docs/build/environment-variables) for a given unit test.

```yml
unit_tests:
- name: my_favorite_unit_test
model: my_favorite_model
overrides:
macros:
is_incremental: false
current_timestamp: "date('2023-01-15')"
vars:
my_name: grace
platforms: ['web', 'mobile']
env_vars:
DBT_ENVIRONMENT_NAME: prod
...
```

#### Macros

You can override the output of any macro in your unit test defition.

There are some macros you _must_ override if the model you're unit testing uses them:
- [`is_incremental`](/docs/build/incremental-models#understanding-the-is_incremental-macro): If you're unit testing an incremental model, you must explicity set `is_incremental` to `true` or `false`. See more docs on unit testing incremental models [here](/docs/build/unit-tests#unit-testing-incremental-models).

```yml
unit_tests:
- name: my_unit_test
model: my_incremental_model
overrides:
macros:
# unit test this model in "full refresh" mode
is_incremental: false
...
```

- [`dbt_utils.star`](/blog/star-sql-love-letter): If you're unit testing a model that uses the `star` macro, you must explicity set `star` to a list of columns. This is because the `star` only accepts a [relation](/reference/dbt-classes#relation) for the `from` argument; the unit test mock input data is injected directly into the model SQL, replacing the `ref('')` or `source('')` function, causing the `star` macro to fail unless overidden.

```yml
unit_tests:
- name: my_other_unit_test
model: my_model_that_uses_star
overrides:
macros:
# explicity set star to relevant list of columns
star: col_a,col_b,col_c
...
```

## Examples
```yml
Expand Down

0 comments on commit 42f7fd2

Please sign in to comment.