### Run dbt Unit Tests with Make Source: https://github.com/equalexperts/dbt-unit-testing/blob/master/jaffle-shop/README.md This command initiates the dbt unit testing process using a Makefile. It assumes Docker is installed and the repository is cloned. ```bash make ``` -------------------------------- ### Example Unit Tests with Simplified Mocking Strategy Source: https://github.com/equalexperts/dbt-unit-testing/blob/master/jaffle-shop/README.md This SQL file contains unit tests for the jaffle_shop project using a simplified mocking strategy. It also relies on documentation rather than database dependencies. ```sql -- tests/unit/tests_using_simplified_mocking_strategy_and_sql_input.sql -- Example tests using simplified mocking strategy ``` -------------------------------- ### Example Unit Tests with Full Mocking Strategy Source: https://github.com/equalexperts/dbt-unit-testing/blob/master/jaffle-shop/README.md This SQL file contains unit tests for the jaffle_shop project using a full mocking strategy. It relies on documentation rather than database dependencies. ```sql -- tests/unit/tests_using_full_mocking_strategy_and_sql_input.sql -- Example tests using full mocking strategy ``` -------------------------------- ### Install dbt-unit-testing Package Source: https://github.com/equalexperts/dbt-unit-testing/blob/master/README.md Instructions for adding the dbt-unit-testing package to your dbt project's packages.yml file. Specifies the Git repository and a specific revision for installation. ```yaml packages: - git: "https://github.com/EqualExperts/dbt-unit-testing" revision: v0.4.12 ``` -------------------------------- ### Example Unit Tests with Pure Mocking Strategy Source: https://github.com/equalexperts/dbt-unit-testing/blob/master/jaffle-shop/README.md This SQL file contains unit tests for the jaffle_shop project using a pure mocking strategy, which is the simplest approach. It relies on documentation rather than database dependencies. ```sql -- tests/unit/tests_using_pure_mocking_strategy_and_sql_input.sql -- Example tests using pure mocking strategy ``` -------------------------------- ### dbt Unit Test Example Source: https://github.com/equalexperts/dbt-unit-testing/blob/master/README.md An example of a dbt unit test using the dbt_unit_testing package. It defines a test for the 'customers' model, mocks its dependencies ('stg_customers', 'stg_orders', 'stg_payments') with sample data, and sets an expectation for the 'customer_lifetime_value' calculation. ```jinja {{ config(tags=['unit-test']) }} {% call dbt_unit_testing.test('customers', 'should sum order values to calculate customer_lifetime_value') %} {% call dbt_unit_testing.mock_ref ('stg_customers') %} select 1 as customer_id, '' as first_name, '' as last_name {% endcall %} {% call dbt_unit_testing.mock_ref ('stg_orders') %} select 1001 as order_id, 1 as customer_id, null as order_date UNION ALL select 1002 as order_id, 1 as customer_id, null as order_date {% endcall %} {% call dbt_unit_testing.mock_ref ('stg_payments') %} select 1001 as order_id, 10 as amount UNION ALL select 1002 as order_id, 10 as amount {% endcall %} {% call dbt_unit_testing.expect() %} select 1 as customer_id, 20 as customer_lifetime_value {% endcall %} {% endcall %} ``` -------------------------------- ### Jinja Mocking with 'include_missing_columns' Option Source: https://github.com/equalexperts/dbt-unit-testing/blob/master/README.md Demonstrates using the 'include_missing_columns' option to automatically infer missing columns based on model and source definitions, simplifying mock setup. ```jinja {% set options = {"include_missing_columns": true} %} {% call dbt_unit_testing.test('customers', 'should show customer_id without orders') %} {% call dbt_unit_testing.mock_ref ('stg_customers', options) %} select 1 as customer_id {% endcall %} {% call dbt_unit_testing.expect() %} select 1 as customer_id {% endcall %} {% endcall %} ``` -------------------------------- ### dbt Unit Test Structure Source: https://github.com/equalexperts/dbt-unit-testing/blob/master/README.md Defines the basic structure of a dbt unit test, including test setup (mocks) and expectations. It uses Jinja templating for defining the test case. ```jinja {{ config(tags=['unit-test']) }} {% call dbt_unit_testing.test ('[Model to Test]','[Test Name]') %} {% call dbt_unit_testing.mock_ref ('[model name]') %} select ... {% endcall %} {% call dbt_unit_testing.mock_source('[source name]') %} select ... {% endcall %} {% call dbt_unit_testing.expect() %} select ... {% endcall %} {% endcall %} ``` -------------------------------- ### Test Incremental Model (Incremental Run) Source: https://github.com/equalexperts/dbt-unit-testing/blob/master/README.md Example of testing an incremental dbt model, specifically targeting the `is_incremental` logic. This test requires the `run_as_incremental: True` option and mocks the model being tested. ```jinja {% call dbt_unit_testing.test('incremental_model', 'incremental test', options={"run_as_incremental": "True"}) %} {% call dbt_unit_testing.mock_ref ('some_model') %} select 10 as c UNION ALL select 20 as c UNION ALL select 30 as c {% endcall %} {% call dbt_unit_testing.mock_ref ('incremental_model') %} select 10 as c {% endcall %} {% call dbt_unit_testing.expect() %} select 20 as c UNION ALL select 30 as c {% endcall %} {% endcall %} ``` -------------------------------- ### Test Incremental Model (Full Refresh) Source: https://github.com/equalexperts/dbt-unit-testing/blob/master/README.md Example of testing an incremental dbt model in full-refresh mode. This test simulates a complete data load without considering existing data. ```jinja {% call dbt_unit_testing.test('incremental_model', 'full refresh test') %} {% call dbt_unit_testing.mock_ref ('some_model') %} select 10 as c UNION ALL select 20 as c UNION ALL select 30 as c {% endcall %} {% call dbt_unit_testing.mock_ref ('incremental_model') %} select 15 as c UNION ALL select 25 as c {% endcall %} {% call dbt_unit_testing.expect() %} select 10 as c UNION ALL select 20 as c UNION ALL select 30 as c {% endcall %} {% endcall %} ``` -------------------------------- ### Use Case: Rounding Column Values for Precision Source: https://github.com/equalexperts/dbt-unit-testing/blob/master/README.md Provides a practical example of using column transformations to round floating-point values, such as `avg_revenue`, to a specific number of decimal places. This addresses precision issues and ensures consistency in data testing. ```SQL SELECT id, AVG(revenue) as avg_revenue FROM raw_financial_data ``` ```Jinja {% set column_transformations = { "avg_revenue": "round(##column##, 5)" } %} {% call dbt_unit_testing.test('financial_model', options={"column_transformations": column_transformations}) %} {% call dbt_unit_testing.mock_ref ('raw_financial_data') %} select 5.0 as revenue UNION ALL select 2.0 as revenue UNION ALL select 3.0 as revenue {% endcall %} {% call dbt_unit_testing.expect() %} select 3.33333 as avg_revenue {% endcall %} {% endcall %} ``` -------------------------------- ### Using dbt_unit_testing.ref Macro Source: https://github.com/equalexperts/dbt-unit-testing/blob/master/README.md Demonstrates how to use the dbt_unit_testing.ref macro within dbt models to reference other models, facilitating dependency management and testing. ```sql select * from {{ dbt_unit_testing.ref('stg_customers') }} ``` -------------------------------- ### Jaffle Shop Overview Source: https://github.com/equalexperts/dbt-unit-testing/blob/master/jaffle-shop/models/overview.md Provides an overview of the jaffle_shop dataset, a fictional ecommerce store used for dbt testing. It includes a link to the dbt project's source code. ```sql /* Data Documentation for Jaffle Shop `jaffle_shop` is a fictional ecommerce store. This [dbt](https://www.getdbt.com/) project is for testing out code. The source code can be found [here](https://github.com/clrcrl/jaffle_shop). */ ``` -------------------------------- ### Using builtins.ref with dbt_utils.star Source: https://github.com/equalexperts/dbt-unit-testing/blob/master/README.md Illustrates how to use the original dbt 'ref' macro via 'builtins.ref' when integrating with macros like 'dbt_utils.star', ensuring compatibility and proper referencing. ```jinja select {{ dbt_utils.star(builtins.ref('some_model')) }} from {{ ref('some_model') }} ``` -------------------------------- ### Specifying Model Versions with dbt_unit_testing.ref Source: https://github.com/equalexperts/dbt-unit-testing/blob/master/README.md Shows how to specify a version for a dbt model when using the dbt_unit_testing.ref macro, either using the 'version' or 'v' parameter. ```jinja {% call dbt_unit_testing.ref('some_model', version=3) %} {% endcall %} or {% call dbt_unit_testing.ref('some_model', v=3) %} {% endcall %} ``` -------------------------------- ### dbt_project.yml Configuration for Unit Tests Source: https://github.com/equalexperts/dbt-unit-testing/blob/master/README.md Shows how to configure default unit testing options, such as input format and separators, within the dbt_project.yml file. ```yaml vars: unit_tests_config: input_format: "csv" column_separator: "|" line_separator: "\n" type_separator: "::" ``` -------------------------------- ### Jinja Mocking with SQL Input Source: https://github.com/equalexperts/dbt-unit-testing/blob/master/README.md Shows how to use dbt_unit_testing macros to mock data using standard SQL SELECT statements, useful for complex data generation or when SQL is preferred. ```jinja {% call dbt_unit_testing.test('customers', 'should show customer_id without orders') %} {% call dbt_unit_testing.mock_ref ('stg_customers') %} select 1 as customer_id, '' as first_name, '' as last_name {% endcall %} {% call dbt_unit_testing.mock_ref ('stg_orders') %} select null::numeric as customer_id, null::numeric as order_id, null as order_date where false {% endcall %} {% call dbt_unit_testing.mock_ref ('stg_payments') %} select null::numeric as order_id, null::numeric as amount where false {% endcall %} {% call dbt_unit_testing.expect() %} select 1 as customer_id {% endcall %} {% endcall %} ``` -------------------------------- ### Run Integration Tests with PostgreSQL Source: https://github.com/equalexperts/dbt-unit-testing/blob/master/integration-tests/README.md Execute the integration tests locally by running the provided make command. This command targets PostgreSQL as the database for the tests. Ensure you are in the `integration-tests` directory before running. ```bash make TARGET=postgres ``` -------------------------------- ### dbt-unit-testing Test Execution with Output Sorting Source: https://github.com/equalexperts/dbt-unit-testing/blob/master/README.md Demonstrates how to execute a dbt unit test using the `dbt_unit_testing.test` macro and specifies an `output_sort_field` to control the order of test results for better readability. ```jinja {% call dbt_unit_testing.test('some_model', 'smoke test', {"output_sort_field": "business_id"}) %} ... {% endcall %} ``` -------------------------------- ### Running dbt Unit Tests Source: https://github.com/equalexperts/dbt-unit-testing/blob/master/README.md Commands for executing dbt unit tests. The first command runs all tests in the project, while the second specifically targets and runs only tests tagged with 'unit-test'. ```bash dbt test ``` ```bash dbt test --select tag:unit-test ``` -------------------------------- ### dbt-unit-testing Configuration Options Source: https://github.com/equalexperts/dbt-unit-testing/blob/master/README.md This section outlines the various configuration options available for dbt-unit-testing, detailing their purpose, default values, and scope of application. These options allow for fine-grained control over how tests are executed and how mock data is handled. ```yaml include_missing_columns: false use_database_models: false input_format: sql column_separator: "," line_separator: "\n" type_separator: "::" use_qualified_sources: false disable_cache: false diff_column: "diff" count_column: "count" run_as_incremental: false column_transformations: {} last_spaces_replace_char: "(space)" ``` -------------------------------- ### Jinja Mocking with CSV Input Source: https://github.com/equalexperts/dbt-unit-testing/blob/master/README.md Demonstrates how to use dbt_unit_testing macros to mock data in CSV format for unit tests. It shows mocking multiple tables and defining expected output. ```jinja {% call dbt_unit_testing.test('customers', 'should sum order values to calculate customer_lifetime_value') %} {% call dbt_unit_testing.mock_ref ('stg_customers', {"input_format": "csv"}) %} customer_id, first_name, last_name 1,'','' {% endcall %} {% call dbt_unit_testing.mock_ref ('stg_orders', {"input_format": "csv"}) %} order_id,customer_id,order_date 1001,1,null 1002,1,null {% endcall %} {% call dbt_unit_testing.mock_ref ('stg_payments', {"input_format": "csv"}) %} order_id,customer_id,order_date 1001,10 1002,10 {% endcall %} {% call dbt_unit_testing.expect({"input_format": "csv"}) %} customer_id,customer_lifetime_value 1,20 {% endcall %} {% endcall %} ``` -------------------------------- ### Handling dbt Dependencies with ref() and source() Source: https://github.com/equalexperts/dbt-unit-testing/blob/master/README.md This snippet demonstrates how to resolve compilation errors related to dbt's ref() and source() macros within conditional blocks by adding a `depends_on` hint. It shows the error message and the required fix. ```jinja Compilation Error in test some_model_test (tests/unit/some_model_test.sql) dbt was unable to infer all dependencies for the model "some_model_test". This typically happens when ref() is placed within a conditional block. To fix this, add the following hint to the top of the model "some_model_test": -- depends_on: {{ ref('some_model') }} ``` ```jinja -- depends_on: {{ ref('some_model') }} {{ config( tags=['unit-test'] ) }} {% call dbt_unit_testing.test('model_being_tested', 'sample test') %} ... ... ... ... ... {% endcall %} ``` -------------------------------- ### Mocking stg_payments Dependency Source: https://github.com/equalexperts/dbt-unit-testing/blob/master/README.md This snippet illustrates mocking the 'stg_payments' dependency, simulating payment records for orders using UNION ALL. ```jinja {% call dbt_unit_testing.mock_ref ('stg_payments') %} select 1001 as order_id, 10 as amount UNION ALL select 1002 as order_id, 10 as amount {% endcall %} ``` -------------------------------- ### Enable Incremental Model Testing Source: https://github.com/equalexperts/dbt-unit-testing/blob/master/README.md Macro to enable testing of incremental dbt models. This macro should be added to your dbt project to facilitate the testing of incremental logic. ```jinja {% macro is_incremental() %} {{ return (dbt_unit_testing.is_incremental()) }} {% endmacro %} ``` -------------------------------- ### dbt Unit Testing Macros Source: https://github.com/equalexperts/dbt-unit-testing/blob/master/README.md Reference for available macros within the dbt-unit-testing framework. Each macro serves a specific purpose in defining, mocking, and asserting test conditions. ```APIDOC dbt_unit_testing.test: description: Defines a Test parameters: - name: Model to Test type: string description: The name of the model being tested. - name: Test Name type: string description: A unique identifier for the test case. dbt_unit_testing.mock_ref: description: Mocks a **model** / **snapshot** / **seed** parameters: - name: model name type: string description: The name of the model, snapshot, or seed to mock. usage: {% call dbt_unit_testing.mock_ref ('[model name]') %} select ... {% endcall %} dbt_unit_testing.mock_source: description: Mocks a **source** parameters: - name: source name type: string description: The name of the source to mock. usage: {% call dbt_unit_testing.mock_source('[source name]') %} select ... {% endcall %} dbt_unit_testing.expect: description: Defines the Test expectations usage: {% call dbt_unit_testing.expect() %} select ... {% endcall %} dbt_unit_testing.expect_no_rows: description: Used to test if the model returns no rows usage: {% call dbt_unit_testing.expect_no_rows() %} {% endcall %} dbt_unit_testing.model: description: Allows the use of the model object within tests. ``` -------------------------------- ### Mocking Specific Model Versions Source: https://github.com/equalexperts/dbt-unit-testing/blob/master/README.md Explains how to mock a specific version of a dbt model using the 'version' parameter in the dbt_unit_testing.mock_ref macro. ```jinja {% call dbt_unit_testing.mock_ref('some_model', version=3) %} select 1 {% endcall %} ``` -------------------------------- ### Mocking stg_orders Dependency Source: https://github.com/equalexperts/dbt-unit-testing/blob/master/README.md This snippet shows how to mock the 'stg_orders' dependency. It uses a UNION ALL to simulate multiple order records associated with a customer. ```jinja {% call dbt_unit_testing.mock_ref ('stg_orders') %} select 1001 as order_id, 1 as customer_id, null as order_date UNION ALL select 1002 as order_id, 1 as customer_id, null as order_date {% endcall %} ``` -------------------------------- ### Mocking stg_customers Dependency Source: https://github.com/equalexperts/dbt-unit-testing/blob/master/README.md This snippet demonstrates how to mock the 'stg_customers' dependency within a dbt unit test. It provides a sample SELECT statement to simulate the data returned by this staging model. ```jinja {% call dbt_unit_testing.mock_ref ('stg_customers') %} select 1 as customer_id, '' as first_name, '' as last_name {% endcall %} ``` -------------------------------- ### Testing Specific Model Versions Source: https://github.com/equalexperts/dbt-unit-testing/blob/master/README.md Demonstrates how to test a specific version of a dbt model using the 'version' parameter within the dbt_unit_testing.test macro. ```jinja {% call dbt_unit_testing.test('some_model', 'should return 1', version=3) %} {% call dbt_unit_testing.expect() %} select 1 {% endcall %} {% endcall %} ``` -------------------------------- ### Multiple dbt Unit Tests in a File Source: https://github.com/equalexperts/dbt-unit-testing/blob/master/README.md Demonstrates how to define multiple unit tests within a single dbt test file by separating each test definition with a UNION ALL statement. This allows for organizing related tests efficiently. ```jinja {{ config(tags=['unit-test']) }} {% call dbt_unit_testing.test ('[Model to Test]','[Test Name]') %} {% call dbt_unit_testing.mock_ref ('[model name]') %} select ... {% endcall %} {% call dbt_unit_testing.mock_source('[source name]') %} select ... {% endcall %} {% call dbt_unit_testing.expect() %} select ... {% endcall %} {% endcall %} UNION ALL {% call dbt_unit_testing.test ('[Model to Test]','[Another Test]') %} {% call dbt_unit_testing.mock_ref ('[model name]') %} select ... {% endcall %} {% call dbt_unit_testing.mock_source('[source name]') %} select ... {% endcall %} {% call dbt_unit_testing.expect() %} select ... {% endcall %} {% endcall %} ``` -------------------------------- ### Global Column Transformations in dbt_project.yml Source: https://github.com/equalexperts/dbt-unit-testing/blob/master/README.md Shows how to configure column transformations globally within the `dbt_project.yml` file. This approach applies specified transformations to all unit tests within the project for particular models. ```yaml vars: unit_tests_config: column_transformations: some_model_name: col_name_1: round(col_name_1, 4) # ... additional transformations for 'some_model_name' another_model_name: # ... transformations for 'another_model_name' ``` -------------------------------- ### Overriding Standard ref and source Macros Source: https://github.com/equalexperts/dbt-unit-testing/blob/master/README.md Provides Jinja code to override the default dbt 'ref' and 'source' macros with the dbt_unit_testing versions. This ensures that the testing framework's macros are used throughout the project. ```jinja {% macro ref() %} {{ return(dbt_unit_testing.ref(*varargs, **kwargs)) }} {% endmacro %} {% macro source() %} {{ return(dbt_unit_testing.source(*varargs, **kwargs)) }} {% endmacro %} ``` -------------------------------- ### Apply Column Transformations in dbt Test Source: https://github.com/equalexperts/dbt-unit-testing/blob/master/README.md Demonstrates how to assign a JSON structure of column transformations to a variable and pass it into the `dbt_unit_testing.test` macro options. This allows for custom data manipulation during testing. ```Jinja {% set column_transformations = { "col_name_1": "round(col_name_1, 4)", "col_name_2": "to_json_string(col_name_2)" } %} {% call dbt_unit_testing.test('some_model_name', options={"column_transformations": column_transformations}) %} ... ``` -------------------------------- ### Jinja Mocking with Custom CSV Separators and Type Casting Source: https://github.com/equalexperts/dbt-unit-testing/blob/master/README.md Illustrates using custom separators and specifying column types (e.g., '::date', '::int') within CSV formatted mock data. ```jinja {% call dbt_unit_testing.test('customers', 'should sum order values to calculate customer_lifetime_value') %} {% call dbt_unit_testing.mock_ref ('stg_customers', {"input_format": "csv"}) %} customer_id | first_name | last_name 1 | '' | '' {% endcall %} {% call dbt_unit_testing.mock_ref ('stg_orders', {"input_format": "csv"}) %} order_id | customer_id | order_date::date 1 | 1 | null 2 | 1 | null {% endcall %} {% call dbt_unit_testing.mock_ref ('stg_payments', {"input_format": "csv"}) %} order_id | amount::int 1 | 10 2 | 10 {% endcall %} {% call dbt_unit_testing.expect({"input_format": "csv"}) %} customer_id | customer_lifetime_value 1 | 20 {% endcall %} {% endcall %} ``` -------------------------------- ### Using ##column## Token for Dynamic Transformations Source: https://github.com/equalexperts/dbt-unit-testing/blob/master/README.md Illustrates the use of the special `##column##` token within column transformation definitions. This token is dynamically replaced with the actual column name, properly quoted for the database adapter, ensuring correct SQL execution. ```yaml vars: unit_tests_config: column_transformations: some_model_name: col_name_1: "round(##column##, 2)" # ... additional transformations ``` -------------------------------- ### dbt Unit Test Expectations Source: https://github.com/equalexperts/dbt-unit-testing/blob/master/README.md Specifies the expected output of a dbt model during a unit test. The framework compares these expectations against the actual model results to identify discrepancies. ```jinja {% call dbt_unit_testing.expect() %} select ... {% endcall %} ``` -------------------------------- ### dbt-unit-testing Schema Definition Source: https://github.com/equalexperts/dbt-unit-testing/blob/master/jaffle-shop/etc/dbdiagram_definition.txt Defines the structure of the 'customers' table, including its columns, data types, and primary key. ```dbt-unit-testing Table customers { id int PK first_name varchar last_name varchar } ``` -------------------------------- ### Defining Test Expectation Source: https://github.com/equalexperts/dbt-unit-testing/blob/master/README.md This snippet defines the expected output for the 'customers' model test. It specifies the 'customer_id' and the calculated 'customer_lifetime_value' that the test should validate. ```jinja {% call dbt_unit_testing.expect() %} select 1 as customer_id, 20 as customer_lifetime_value {% endcall %} ``` -------------------------------- ### Orders Status Documentation Source: https://github.com/equalexperts/dbt-unit-testing/blob/master/jaffle-shop/models/docs.md Defines the possible statuses for orders within the system. This documentation is used to explain the meaning of the 'status' field in the orders data model. ```sql -- Orders can be one of the following statuses: -- -- | status | description | -- |----------------|------------------------------------------------------------------------------------------------------------------------| -- | placed | The order has been placed but has not yet left the warehouse | -- | shipped | The order has ben shipped to the customer and is currently in transit | -- | completed | The order has been received by the customer | -- | return_pending | The customer has indicated that they would like to return the order, but it has not yet been received at the warehouse | -- | returned | The order has been returned by the customer and received at the warehouse | ``` -------------------------------- ### dbt-unit-testing Schema Definition Source: https://github.com/equalexperts/dbt-unit-testing/blob/master/jaffle-shop/etc/dbdiagram_definition.txt Defines the structure of the 'orders' table, including its columns, data types, and primary key. ```dbt-unit-testing Table orders { id int PK user_id int order_date date status varchar } ``` -------------------------------- ### dbt-unit-testing Schema Relationships Source: https://github.com/equalexperts/dbt-unit-testing/blob/master/jaffle-shop/etc/dbdiagram_definition.txt Defines the foreign key relationship between the 'orders' and 'customers' tables, linking orders to customers via user_id. ```dbt-unit-testing Ref: orders.user_id > customers.id ``` -------------------------------- ### Convert Struct to JSON String in BigQuery Source: https://github.com/equalexperts/dbt-unit-testing/blob/master/README.md Demonstrates transforming a BigQuery struct column into a JSON string using column transformations within dbt-unit-testing. This is crucial for performing standard SQL operations like grouping and EXCEPT on complex data types during tests. ```SQL SELECT user_id, activity_details -- struct column FROM raw_user_activity ``` ```Jinja {% set column_transformations = { "activity_details": "to_json_string(##column##)" } %} {% call dbt_unit_testing.test('user_activity_model', options={"column_transformations": column_transformations}) %} -- Test cases and assertions here {% endcall %} ``` -------------------------------- ### dbt-unit-testing Schema Definition Source: https://github.com/equalexperts/dbt-unit-testing/blob/master/jaffle-shop/etc/dbdiagram_definition.txt Defines the structure of the 'payments' table, including its columns and data types. ```dbt-unit-testing Table payments { id int order_id int payment_method int amount int } ``` -------------------------------- ### Define Column Transformations in JSON Source: https://github.com/equalexperts/dbt-unit-testing/blob/master/README.md Specifies how to define column transformations using a JSON structure. This structure is passed into the unit test options to apply transformations before test execution. ```Json { "col_name_1": "round(col_name_1, 4)", "col_name_2": "to_json_string(col_name_2)" } ``` -------------------------------- ### Accessing Model Object in dbt Tests Source: https://github.com/equalexperts/dbt-unit-testing/blob/master/README.md Explains how to correctly access the model object within dbt models when using dbt-unit-testing. It highlights the issue where the `model` object refers to the test itself during test runs and provides the solution using the `dbt_unit_testing.model` macro. ```SQL select model.name as model_name from {{ ref('some_model') }} ``` ```SQL select dbt_unit_testing.model().name as model_name from {{ ref('some_model') }} ``` -------------------------------- ### dbt-unit-testing Spaces at End of Values Replacement Source: https://github.com/equalexperts/dbt-unit-testing/blob/master/README.md Illustrates how to configure the `last_spaces_replace_char` variable to replace trailing spaces in test result values with a specified character, improving the visibility of differences. ```yaml vars: unit_tests_config: last_spaces_replace_char: "." ``` -------------------------------- ### dbt-unit-testing Schema Relationships Source: https://github.com/equalexperts/dbt-unit-testing/blob/master/jaffle-shop/etc/dbdiagram_definition.txt Defines the foreign key relationship between the 'payments' and 'orders' tables, linking payments to orders via order_id. ```dbt-unit-testing Ref: payments.order_id > orders.id ``` -------------------------------- ### dbt Unit Test Expect No Rows Source: https://github.com/equalexperts/dbt-unit-testing/blob/master/README.md A specialized expectation macro used to assert that a dbt model should return no rows. This is useful for testing scenarios where an empty result set is the expected outcome. ```jinja {% call dbt_unit_testing.expect_no_rows() %} {% endcall %} ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.