From 1938b58592888420bac18321355b71b69a61292f Mon Sep 17 00:00:00 2001 From: mirnawong1 Date: Mon, 13 Jan 2025 17:02:45 +0000 Subject: [PATCH 1/3] add callout tip --- website/docs/docs/build/unit-tests.md | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/website/docs/docs/build/unit-tests.md b/website/docs/docs/build/unit-tests.md index b7123fa35d6..1cda3ef71c7 100644 --- a/website/docs/docs/build/unit-tests.md +++ b/website/docs/docs/build/unit-tests.md @@ -10,9 +10,6 @@ keywords: - - - Historically, dbt's test coverage was confined to [“data” tests](/docs/build/data-tests), assessing the quality of input data or resulting datasets' structure. However, these tests could only be executed _after_ building a model. Starting in dbt Core v1.8, we have introduced an additional type of test to dbt - unit tests. In software programming, unit tests validate small portions of your functional code, and they work much the same way here. Unit tests allow you to validate your SQL modeling logic on a small set of static inputs _before_ you materialize your full model in production. Unit tests enable test-driven development, benefiting developer efficiency and code reliability. @@ -219,10 +216,19 @@ dbt test --select test_is_valid_email_address Your model is now ready for production! Adding this unit test helped catch an issue with the SQL logic _before_ you materialized `dim_customers` in your warehouse and will better ensure the reliability of this model in the future. - ## Unit testing incremental models -When configuring your unit test, you can override the output of macros, vars, or environment variables. This enables you to unit test your incremental models in "full refresh" and "incremental" modes. +When configuring your unit test, you can override the output of macros, vars, or environment variables. This enables you to unit test your incremental models in "full refresh" and "incremental" modes. + +:::tip +Incremental models need to exist in the database first before running unit tests or doing a `dbt build`. Use the [`--empty` flag](/reference/commands/build#the---empty-flag) to build an empty version of the models to save warehouse spend. You can also optionally select only your incremental models using the [`--select` flag](/reference/node-selection/syntax#shorthand). + + ```shell + dbt run --select "config.materialized:incremental" --empty + ``` + + After running the command, you can then perform a regular `dbt build` for that model and then run your unit test +::: When testing an incremental model, the expected output is the __result of the materialization__ (what will be merged/inserted), not the resulting model itself (what the final table will look like after the merge/insert). From f2190c6eca72d044801f53be3450ebc6dce4700d Mon Sep 17 00:00:00 2001 From: Mirna Wong <89008547+mirnawong1@users.noreply.github.com> Date: Mon, 13 Jan 2025 17:12:28 +0000 Subject: [PATCH 2/3] Update website/docs/docs/build/unit-tests.md Co-authored-by: Matt Shaver <60105315+matthewshaver@users.noreply.github.com> --- website/docs/docs/build/unit-tests.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/website/docs/docs/build/unit-tests.md b/website/docs/docs/build/unit-tests.md index 1cda3ef71c7..020f780dd84 100644 --- a/website/docs/docs/build/unit-tests.md +++ b/website/docs/docs/build/unit-tests.md @@ -227,7 +227,7 @@ Incremental models need to exist in the database first before running unit tests dbt run --select "config.materialized:incremental" --empty ``` - After running the command, you can then perform a regular `dbt build` for that model and then run your unit test + After running the command, you can then perform a regular `dbt build` for that model and then run your unit test. ::: When testing an incremental model, the expected output is the __result of the materialization__ (what will be merged/inserted), not the resulting model itself (what the final table will look like after the merge/insert). From 1275b30ebc5fc1f033e92858db7fd7f889fbb9bd Mon Sep 17 00:00:00 2001 From: Mirna Wong <89008547+mirnawong1@users.noreply.github.com> Date: Mon, 13 Jan 2025 17:14:36 +0000 Subject: [PATCH 3/3] Update website/docs/docs/build/unit-tests.md Co-authored-by: Matt Shaver <60105315+matthewshaver@users.noreply.github.com> --- website/docs/docs/build/unit-tests.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/website/docs/docs/build/unit-tests.md b/website/docs/docs/build/unit-tests.md index 020f780dd84..4a92a5792c9 100644 --- a/website/docs/docs/build/unit-tests.md +++ b/website/docs/docs/build/unit-tests.md @@ -220,7 +220,7 @@ Your model is now ready for production! Adding this unit test helped catch an is When configuring your unit test, you can override the output of macros, vars, or environment variables. This enables you to unit test your incremental models in "full refresh" and "incremental" modes. -:::tip +:::note Incremental models need to exist in the database first before running unit tests or doing a `dbt build`. Use the [`--empty` flag](/reference/commands/build#the---empty-flag) to build an empty version of the models to save warehouse spend. You can also optionally select only your incremental models using the [`--select` flag](/reference/node-selection/syntax#shorthand). ```shell