-
Notifications
You must be signed in to change notification settings - Fork 969
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add docs for format: sql unit testing
- Loading branch information
1 parent
63f080f
commit 813c322
Showing
3 changed files
with
74 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,6 +17,7 @@ To run only your unit tests, use the command: | |
- We currently only support adding unit tests to models in your _current_ project. | ||
- If your model has multiple versions, by default the unit test will run on *all* versions of your model. Read [unit testing versioned models](#unit-testing-versioned-models) for more information. | ||
- Unit tests must be defined in a YML file in your `models/` directory. | ||
- If you want to unit test a model that depends on an ephemeral model, you must use `format: sql` for that input. | ||
|
||
<file name='dbt_project.yml'> | ||
|
||
|
@@ -33,22 +34,20 @@ unit_tests: | |
tags: <string> | [<string>] | ||
given: | ||
- input: <ref_or_source_call> # optional for seeds | ||
format: dict | csv | ||
# if format csv, either define dictionary of rows or name of fixture | ||
rows: | ||
- {dictionary} | ||
fixture: <fixture-name> | ||
format: dict | csv | sql | ||
# either define rows inline or name of fixture | ||
rows: {dictionary} | <string> | ||
fixture: <fixture-name> # sql or csv | ||
- input: ... # declare additional inputs | ||
expect: | ||
format: dict | csv | ||
# if format csv, either define dictionary of rows or name of fixture | ||
rows: | ||
- {dictionary} | ||
fixture: <fixture-name> | ||
format: dict | csv | sql | ||
# either define rows inline of rows or name of fixture | ||
rows: {dictionary} | <string> | ||
fixture: <fixture-name> # sql or csv | ||
overrides: # optional: configuration for the dbt execution environment | ||
macros: | ||
is_incremental: true | false | ||
dbt_utils.current_timestamp: str | ||
dbt_utils.current_timestamp: <string> | ||
# ... any other jinja function from https://docs.getdbt.com/reference/dbt-jinja-functions | ||
# ... any other context property | ||
vars: {dictionary} | ||
|
@@ -109,3 +108,26 @@ unit_tests: | |
fixture: valid_email_address_fixture_output | ||
|
||
``` | ||
|
||
```yml | ||
|
||
unit_tests: | ||
- name: test_is_valid_email_address # this is the unique name of the test | ||
model: dim_customers # name of the model I'm unit testing | ||
given: # the mock data for your inputs | ||
- input: ref('stg_customers') | ||
rows: | ||
- {email: [email protected], email_top_level_domain: example.com} | ||
- {email: [email protected], email_top_level_domain: unknown.com} | ||
- {email: badgmail.com, email_top_level_domain: gmail.com} | ||
- {email: missingdot@gmailcom, email_top_level_domain: gmail.com} | ||
- input: ref('top_level_email_domains') | ||
format: sql | ||
rows: | | ||
select 'example.com' as tld union all | ||
select 'gmail.com' as tld | ||
expect: # the expected output given the inputs above | ||
format: sql | ||
fixture: valid_email_address_fixture_output | ||
|
||
``` |