Reuse mock-ref in multiple unit tests
darian-heede opened this issue · 2 comments
darian-heede commented
Hi there,
first off, I would like to thank you for this great package!
Is there a way of reusing a mock-ref for multiple unit-tests combined using UNION ALL
without having to set it in every dbt_unit_testing.test()
call?
The following example reuses the mock-ref mock-a in both unit tests:
{% call dbt_unit_testing.test('test-a', 'Test A') %}
{% call dbt_unit_testing.mock_ref('mock-a') %}
...
{% endcall %}
{% call dbt_unit_testing.mock_ref('mock-b') %}
...
{% endcall %}
{% call dbt_unit_testing.expect() %}
...
{% endcall %}
{% endcall %}
UNION ALL
{% call dbt_unit_testing.test('test-b', 'Test B') %}
{% call dbt_unit_testing.mock_ref('mock-a') %}
...
{% endcall %}
{% call dbt_unit_testing.mock_ref('mock-c') %}
...
{% endcall %}
{% call dbt_unit_testing.expect() %}
...
{% endcall %}
{% endcall %}
It would be great not having to repeat the mock-a definition for every unit test.
psousa50 commented
You can define a variable with the value of your mock, like this:
{% set mock_a %}
{% call dbt_unit_testing.mock_ref('mock-a') %}
...
{% endcall %}
{% endset %}
{% call dbt_unit_testing.test('test-a', 'Test A') %}
{{ mock_a }}
{% call dbt_unit_testing.mock_ref('mock-b') %}
...
{% endcall %}
{% call dbt_unit_testing.expect() %}
...
{% endcall %}
{% endcall %}
UNION ALL
{% call dbt_unit_testing.test('test-b', 'Test B') %}
{{ mock_a }}
{% call dbt_unit_testing.mock_ref('mock-c') %}
...
{% endcall %}
{% call dbt_unit_testing.expect() %}
...
{% endcall %}
{% endcall %}
Hope it helps
darian-heede commented
Hi @psousa50 , this is exactly what I was looking for, thanks!