You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+47-6Lines changed: 47 additions & 6 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -154,6 +154,23 @@ UNION ALL
154
154
{% endcall %}
155
155
```
156
156
157
+
### Expectations
158
+
159
+
The expectations are the results you expect from the model. The framework compares the expectations with the actuals and shows the differences in the test report.
160
+
161
+
```jinja
162
+
{% call dbt_unit_testing.expect() %}
163
+
select ...
164
+
{% endcall %}
165
+
```
166
+
167
+
You can use the macro `expect_no_rows` to test if the model returns no rows:
168
+
169
+
```jinja
170
+
{% call dbt_unit_testing.expect_no_rows() %}
171
+
{% endcall %}
172
+
```
173
+
157
174
## Running tests
158
175
159
176
The framework leverages the dbt test command to run the tests. You can run all the tests in your project with the following command:
@@ -170,12 +187,13 @@ dbt test --select tag:unit-test
| dbt_unit_testing.mock_ref | Mocks a **model** / **snapshot** / **seed**|
194
+
| dbt_unit_testing.mock_source | Mocks a **source**|
195
+
| dbt_unit_testing.expect | Defines the Test expectations |
196
+
| dbt_unit_testing.expect_no_rows | Used to test if the model returns no rows |
179
197
180
198
## Test Examples
181
199
@@ -701,6 +719,7 @@ In this example, the `activity_details` column, which is a struct, is transforme
701
719
|**count_column**| The name of the `count` column in the test report | count| project/test |
702
720
|**run_as_incremental**| Runs the model in `incremental` mode (it has no effect if the model is not incremental) | false| project/test |
703
721
|**column_transformations**| A JSON structure specifying the desired transformations for each column. See [Column Transformations](#column-transformations) for more details. | {}| project/test |
722
+
| last_spaces_replace_char | Replace the spaces at the end of the values with another character. See [Test Feedback](#test-feedback) for more details. | (space) | project/test |
704
723
705
724
Notes:
706
725
@@ -740,6 +759,28 @@ Rows mismatch:
740
759
741
760
The first line was not on the model, but the second line was.
742
761
762
+
### Spaces at the end of the diff values
763
+
764
+
It can be hard to spot the difference when the values have spaces at the end. To avoid this, you can use the option `last_spaces_replace_char` to replace the spaces at the end of the values with another character:
765
+
766
+
```yaml
767
+
vars:
768
+
unit_tests_config:
769
+
last_spaces_replace_char: "."
770
+
```
771
+
772
+
This will replace the spaces at the end of the values with a dot. The result will be displayed like this:
773
+
774
+
```yaml
775
+
MODEL: customers
776
+
TEST: should sum order values to calculate customer_lifetime_value
777
+
Rows mismatch:
778
+
| diff | count | some_column |
779
+
| ---- | ----- | ----------- |
780
+
| + | 1 | John |
781
+
| - | 1 | John.. |
782
+
```
783
+
743
784
# Known Limitations
744
785
745
786
- You can not have a *model* with the same name as a *source* or a *seed* (unless you set the *use_qualified_sources* option to *true*).
0 commit comments