Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[CT-3146] [Implementation] updating the unit-tests block (to start with test name instead of model) #8698

Closed
1 task done
Tracked by #8283
graciegoheen opened this issue Sep 22, 2023 · 2 comments
Closed
1 task done
Tracked by #8283
Assignees
Labels
user docs [docs.getdbt.com] Needs better documentation

Comments

@graciegoheen
Copy link
Contributor

graciegoheen commented Sep 22, 2023

Housekeeping

  • I am a maintainer of dbt-core

Short description

From #8606

Current the unit test spec is as follows:

unit:
  - model: my_model # name of the model I'm unit testing
    tests:
     - name: test_is_valid_email_address # this is the unique name of the test
       given: # optional: list of inputs to provide as fixtures
        - input: ref('users')
          rows:
           - {user_id: 1, email: cool@example.com,     email_top_level_domain: example.com}
           - {user_id: 2, email: cool@unknown.com,     email_top_level_domain: unknown.com}
           - {user_id: 3, email: badgmail.com,         email_top_level_domain: gmail.com}
           - {user_id: 4, email: missingdot@gmailcom,  email_top_level_domain: gmail.com}
         - input: ref('top_level_domains')
           rows:
            - {tld: example.com}
            - {tld: gmail.com}
       expect: # required: the expected output given the inputs above
        - {user_id: 1, is_valid_email_address: true}
        - {user_id: 2, is_valid_email_address: false}
        - {user_id: 3, is_valid_email_address: false}
        - {user_id: 4, is_valid_email_address: false}
    - name: test_another_column
      ...

we should adjust it so that the block is

  1. named unit-tests: instead of unit:
  2. starts with the test name instead of the model name

the final spec should look like this:

unit-tests:
  - name: test_is_valid_email_address # this is the unique name of the test
    model: my_model # name of the model I'm unit testing
    given: # optional: list of inputs to provide as fixtures
      - input: ref('users')
        rows:
         - {user_id: 1, email: cool@example.com,     email_top_level_domain: example.com}
         - {user_id: 2, email: cool@unknown.com,     email_top_level_domain: unknown.com}
         - {user_id: 3, email: badgmail.com,         email_top_level_domain: gmail.com}
         - {user_id: 4, email: missingdot@gmailcom,  email_top_level_domain: gmail.com}
      - input: ref('top_level_domains')
        rows:
         - {tld: example.com}
         - {tld: gmail.com}
    expect: # required: the expected output given the inputs above
      - {user_id: 1, is_valid_email_address: true}
      - {user_id: 2, is_valid_email_address: false}
      - {user_id: 3, is_valid_email_address: false}
      - {user_id: 4, is_valid_email_address: false}
  - name: test_another_column
    ...

Acceptance criteria

  • unit test block is called unit-tests:
  • unit test block starts with test name (instead of model name)

Impact to Other Teams

None

Will backports be required?

No

Context

No response

@graciegoheen graciegoheen added the user docs [docs.getdbt.com] Needs better documentation label Sep 22, 2023
@github-actions github-actions bot changed the title [Implementation] updating the unit-tests block (to start with test name instead of model) [CT-3146] [Implementation] updating the unit-tests block (to start with test name instead of model) Sep 22, 2023
@graciegoheen
Copy link
Contributor Author

  • changes the hierarchy, which will affect parsing
  • already storing by the unit test in the manifest → so no expected manifest structure changes

@emmyoop
Copy link
Member

emmyoop commented Nov 7, 2023

Resolved by #8988 and #8966

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
user docs [docs.getdbt.com] Needs better documentation
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants