Skip to content

Commit 1425cd2

Browse files
committed
Usage documentation for generate_unit_test_template macro
1 parent 3a660ea commit 1425cd2

File tree

1 file changed

+42
-0
lines changed

1 file changed

+42
-0
lines changed

README.md

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@ Macros that generate dbt code, and log it to the command line.
2626
- [generate_model_import_ctes (source)](#generate_model_import_ctes-source)
2727
- [Arguments:](#arguments-5)
2828
- [Usage:](#usage-5)
29+
- [generate_unit_test_template (source)](#generate_unit_test_template-source)
30+
- [Arguments:](#arguments-6)
31+
- [Usage:](#usage-6)
2932
- [Contributing](#contributing)
3033

3134
# Installation instructions
@@ -394,6 +397,45 @@ select * from final
394397

395398
4. Replace the contents of the model's current SQL file with the compiled or logged code
396399

400+
## generate_unit_test_template ([source](macros/generate_unit_test_template.sql))
401+
402+
This macro generates the unit testing YAML for a given model with all references included as `given` inputs (along with their columns), plus the columns within the expected output.
403+
404+
### Arguments:
405+
406+
- `model_name` (required): The model you wish to generate unit testing YAML for.
407+
- `inline_columns` (optional, default=False): Whether you want all columns on the same line.
408+
409+
### Usage:
410+
411+
1. Create a model with your original SQL query
412+
2. Call the macro as an [operation](https://docs.getdbt.com/docs/using-operations):
413+
414+
```
415+
$ dbt run-operation generate_unit_test_template --args '{"model_name": "order_items", "inline_columns": true}'
416+
```
417+
418+
3. The new YAML - with all given inputs included - will be logged to the command line
419+
420+
```yaml
421+
unit_tests:
422+
- name: unit_test_order_items
423+
model: order_items
424+
425+
given:
426+
- input: ref("stg_order_items")
427+
rows:
428+
- col_a:
429+
col_b:
430+
431+
expect:
432+
rows:
433+
- id:
434+
```
435+
436+
4. Create a new YAML file with the compiled or logged code.
437+
5. Add column values for the given inputs and expected output.
438+
397439
## Contributing
398440
399441
To contirbute code to this package, please follow the steps outlined in the `integration_tests` directory's [README](https://github.com/dbt-labs/dbt-codegen/blob/main/integration_tests/README.md) file.

0 commit comments

Comments
 (0)