Open graciegoheen opened 11 months ago
Did some more digging, and figured out the proper syntax!
unit_tests:
- name: a # this is the unique name of the test
model: dim_wizards # name of the model I'm unit testing
given: # the mock data for your inputs
- input: ref('stg_wizards')
rows:
- {wizard_id: 1, email: cool@example.com, email_top_level_domain: example.com}
- {wizard_id: 2, email: cool@unknown.com, email_top_level_domain: unknown.com}
- {wizard_id: 3, email: badgmail.com, email_top_level_domain: gmail.com}
- {wizard_id: 4, email: missingdot@gmailcom, email_top_level_domain: gmail.com}
- input: ref('top_level_email_domains')
rows:
- {tld: example.com}
- {tld: gmail.com}
- input: ref('stg_worlds')
rows: []
expect: # the expected output given the inputs above
rows:
- {wizard_id: 1, is_valid_email_address: true}
- {wizard_id: 2, is_valid_email_address: false}
- {wizard_id: 3, is_valid_email_address: false}
- {wizard_id: 4, is_valid_email_address: false}
@dbeatty10 Do we feel comfortable closing this out (and adding to our planned documentation) - or do you think there's any further improvement we could do here?
One enhancement I can think of, is not having to supply the input at all:
unit_tests:
- name: a # this is the unique name of the test
model: dim_wizards # name of the model I'm unit testing
given: # the mock data for your inputs
- input: ref('stg_wizards')
rows:
- {wizard_id: 1, email: cool@example.com, email_top_level_domain: example.com}
- {wizard_id: 2, email: cool@unknown.com, email_top_level_domain: unknown.com}
- {wizard_id: 3, email: badgmail.com, email_top_level_domain: gmail.com}
- {wizard_id: 4, email: missingdot@gmailcom, email_top_level_domain: gmail.com}
- input: ref('top_level_email_domains')
rows:
- {tld: example.com}
- {tld: gmail.com}
expect: # the expected output given the inputs above
rows:
- {wizard_id: 1, is_valid_email_address: true}
- {wizard_id: 2, is_valid_email_address: false}
- {wizard_id: 3, is_valid_email_address: false}
- {wizard_id: 4, is_valid_email_address: false}
Note: if you don't include a seed direct parent, we'll use the seed
Is this your first time submitting a feature request?
Describe the feature
Let's say I'm working in the above dbt project.
I want to add a unit test to my
dim_wizards
- specifically, I want to test myis_valid_email_address
logic:Even though
dim_wizards
depends on three nodes:stg_worlds
modelstg_wizards
modeltop_level_email_domains
seedI only want to supply mock input data for the nodes that are relevant to my test.
In this case, that's just a few columns from
stg_wizards
and a column fromtop_level_email_domains
. Thestg_worlds
model is completely irrelevant for this unit test.If I don't include
stg_worlds
in my unit test definition, however,dbt build
doesn't work quite right:I think this error is because:
stg_worlds
If I reference
stg_worlds
in my unit test definition, but don't supply any mock data...I get a different error:
If I don't include
rows:
at all...I get a different error:
Describe alternatives you've considered
The work-around I used was adding a dummy single row for
stg_worlds
:I would like some way to be able to input no mock data for certain inputs.
Who will this benefit?
No response
Are you interested in contributing this feature?
No response
Anything else?
No response