-
Notifications
You must be signed in to change notification settings - Fork 979
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 (#5281)
## 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). --> Closes #5289 Coming soon (see core PR [here](dbt-labs/dbt-core#9873)) we are introducing a new format for defining mock data for unit tests - `format: sql`. This PR adds documentation for that new format. ## 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/vercel.json` - [ ] Run link testing locally with `npm run build` to update the links that point to deleted pages
- Loading branch information
Showing
3 changed files
with
99 additions
and
16 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 | ||
|
||
``` |