dbt-labs / dbt-jsonschema

Apache License 2.0
109 stars 40 forks source link

[unit testing] create new top level "unit_tests:" #106

Closed graciegoheen closed 4 months ago

graciegoheen commented 7 months ago

With the introduction of unit testing (coming to dbt-core in 1.8), we should create a new top level unit_tests: schema yml block.

Current spec as follows:

unit_tests:
  - name: <test-name> # this is the unique name of the test
    model: <model-name> 
    config: 
      meta: {dictionary}
      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>
      - 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>
    overrides: # optional: configuration for the dbt execution environment
      macros:
        is_incremental: true | false
        dbt_utils.current_timestamp: str
      # ... any other jinja function from https://docs.getdbt.com/reference/dbt-jinja-functions
          # ... any other context property
        vars: {dictionary}
        env_vars: {dictionary}
  - name: <test-name> ... # declare additional unit tests

More examples here