https://github.com/yu-iskw/dbt-unittest
A dbt package provides macros for unit testing, inspired by python's unittest module
https://github.com/yu-iskw/dbt-unittest
dbt dbt-package unit-testing unittest
Last synced: 1 day ago
JSON representation
A dbt package provides macros for unit testing, inspired by python's unittest module
- Host: GitHub
- URL: https://github.com/yu-iskw/dbt-unittest
- Owner: yu-iskw
- License: apache-2.0
- Created: 2022-07-06T04:55:09.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2024-12-16T08:56:55.000Z (10 months ago)
- Last Synced: 2025-03-29T05:04:57.854Z (6 months ago)
- Topics: dbt, dbt-package, unit-testing, unittest
- Language: Shell
- Homepage: https://docs.getdbt.com/blog/unit-testing-dbt-packages
- Size: 40 KB
- Stars: 25
- Watchers: 2
- Forks: 2
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE
- Codeowners: .github/CODEOWNERS
Awesome Lists containing this project
README
# dbt-unittest
This is a dbt package to enhance dbt package development by providing unit testing macros.- [Installation Instructions](#installation-instructions)
- [Requirements](#requirements)
- [Macros in the dbt package](#macros-in-the-dbt-package)
* [`assert_true`](#assert_true)
* [`assert_false`](#assert_false)
* [`assert_is_none`](#assert_is_none)
* [`assert_is_not_none`](#assert_is_not_none)
* [`assert_equals`](#assert_equals)
* [`assert_not_equals`](#assert_not_equals)
* [`assert_in`](#assert_in)
* [`assert_not_in`](#assert_not_in)
* [`assert_list_equals`](#assert_list_equals)
* [`assert_dict_equals`](#assert_dict_equals)
* [Comparison macros](#comparison-macros)
* [`equals`](#equals)
* [`not_equals`](#not_equals)
* [`contains`](#contains)
* [`not_in`](#not_in)
* [`is_true`](#is_true)
* [`is_false`](#is_false)
* [`is_none`](#is_none)
* [`is_not_none`](#is_not_none)
* [`list_equals`](#list_equals)
* [`dict_equals`](#dict_equals)## Installation Instructions
Check [dbt Hub](https://hub.getdbt.com/yu-iskw/dbt_unittest/latest/) for the latest installation instructions.## Requirements
- dbt-core: 1.0.0 or later## Macros in the dbt package
### `assert_true`
Test that expr is true.**Usage:**
```sql
{{ dbt_unittest.assert_true(true) }}
{{ dbt_unittest.assert_true(1 == 1) }}
```### `assert_false`
Test that expr is false.**Usage:**
```sql
{{ dbt_unittest.assert_false(false) }}
{{ dbt_unittest.assert_false(1 != 1) }}
```### `assert_is_none`
Test that expr is None.**Usage:**
```sql
{{ dbt_unittest.assert_is_none(none) }}
```### `assert_is_not_none`
Test that expr is not None.**Usage:**
```sql
{{ dbt_unittest.assert_is_not_none(none) }}
```### `assert_equals`
Test that first and second are equal.
If the values do not compare equal, the test will fail.**Usage:**
```sql
{{ dbt_unittest.assert_equals("foo", "bar") }}
```### `assert_not_equals`
Test that first and second are not equal.
If the values do compare equal, the test will fail.**Usage:**
```sql
{{ dbt_unittest.assert_not_equals("foo", "bar") }}
```### `assert_in`
Test that member is in container.**Usage:**
```sql
{{ dbt_unittest.assert_in(1, [1, 2, 3]) }}
```### `assert_not_in`
Test that member is not in container.**Usage:**
```sql
{{ dbt_unittest.assert_not_in(4, [1, 2, 3]) }}
```### `assert_list_equals`
Tests that two lists are equal.**Usage:**
```sql
{{ dbt_unittest.assert_list_equals([1, 2, 3], [4, 5]) }}
```### `assert_dict_equals`
Test that two dictionaries are equal.**Usage:**
```sql
{{ dbt_unittest.assert_dict_equals({"k": 1}, {"k": 1}) }}
```## Comparison macros
### `equals`
Return true if two values are equal.**Usage:**
```sql
{% set result = dbt_unittest.equals(1, 1) %}
```### `not_equals`
Return true if two values are not equal.**Usage:**
```sql
{% set result = dbt_unittest.not_equals(1, 2) %}
```### `contains`
Return true if a value exists within a collection.**Usage:**
```sql
{% set result = dbt_unittest.contains(1, [1, 2, 3]) %}
```### `not_in`
Return true if a value does not exist within a collection.**Usage:**
```sql
{% set result = dbt_unittest.not_in(4, [1, 2, 3]) %}
```### `is_true`
Return true when the value is strictly `true`.**Usage:**
```sql
{% set result = dbt_unittest.is_true(true) %}
```### `is_false`
Return true when the value is strictly `false`.**Usage:**
```sql
{% set result = dbt_unittest.is_false(false) %}
```### `is_none`
Return true if the value is `None`.**Usage:**
```sql
{% set result = dbt_unittest.is_none(none) %}
```### `is_not_none`
Return true if the value is not `None`.**Usage:**
```sql
{% set result = dbt_unittest.is_not_none(1) %}
```### `list_equals`
Return true if two lists are equal. Lists may contain nested lists or dictionaries.**Usage:**
```sql
{% set result = dbt_unittest.list_equals([1, 2], [1, 2]) %}
```### `dict_equals`
Return true if two dictionaries are equal. Dictionaries may contain nested dictionaries or lists.**Usage:**
```sql
{% set result = dbt_unittest.dict_equals({'a': 1}, {'a': 1}) %}
```## Contributors