From 66d972db0346a2741070eb1922e65abec790957d Mon Sep 17 00:00:00 2001 From: Grace Goheen Date: Thu, 22 Feb 2024 15:17:55 -0700 Subject: [PATCH 1/2] add more info to overrides for unit testing --- .../resource-properties/unit-tests.md | 55 ++++++++++++++++++- 1 file changed, 54 insertions(+), 1 deletion(-) diff --git a/website/docs/reference/resource-properties/unit-tests.md b/website/docs/reference/resource-properties/unit-tests.md index 1d256e89166..068a3258bcd 100644 --- a/website/docs/reference/resource-properties/unit-tests.md +++ b/website/docs/reference/resource-properties/unit-tests.md @@ -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](https://docs.getdbt.com/docs/build/jinja-macros#macros), [project variables](https://docs.getdbt.com/docs/build/project-variables), or [environment variables](https://docs.getdbt.com/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 your unit testing uses them: + - [`is_incremental`](https://docs.getdbt.com/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](https://docs.getdbt.com/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`](https://docs.getdbt.com/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](https://docs.getdbt.com/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 From a17d87880cb91d18812952b574ba121b084e21f4 Mon Sep 17 00:00:00 2001 From: Grace Goheen <53586774+graciegoheen@users.noreply.github.com> Date: Fri, 23 Feb 2024 09:57:43 -0700 Subject: [PATCH 2/2] Apply suggestions from code review Co-authored-by: Doug Beatty <44704949+dbeatty10@users.noreply.github.com> Co-authored-by: Matt Shaver <60105315+matthewshaver@users.noreply.github.com> --- website/docs/reference/resource-properties/unit-tests.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/website/docs/reference/resource-properties/unit-tests.md b/website/docs/reference/resource-properties/unit-tests.md index 068a3258bcd..8f05cb021b5 100644 --- a/website/docs/reference/resource-properties/unit-tests.md +++ b/website/docs/reference/resource-properties/unit-tests.md @@ -155,7 +155,7 @@ When `format: csv`, can either supply: ### Overrides -When configuring your unit test, you can override the output of [macros](https://docs.getdbt.com/docs/build/jinja-macros#macros), [project variables](https://docs.getdbt.com/docs/build/project-variables), or [environment variables](https://docs.getdbt.com/docs/build/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 @@ -179,8 +179,8 @@ unit_tests: You can override the output of any macro in your unit test defition. -There are some macros you _must_ override if the model your unit testing uses them: - - [`is_incremental`](https://docs.getdbt.com/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](https://docs.getdbt.com/docs/build/unit-tests#unit-testing-incremental-models). +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 @@ -195,7 +195,7 @@ There are some macros you _must_ override if the model your unit testing uses th ``` - - [`dbt_utils.star`](https://docs.getdbt.com/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](https://docs.getdbt.com/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. + - [`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