# Automate macro testing before model run

**URL:** <https://discourse.getdbt.com/t/automate-macro-testing-before-model-run/13930>\
**Category:** Help\
**Tags:** jinja, best-practice, macros, dbt-core\
**Created:** [June 24, 2024, 10:21am UTC](https://discourse.getdbt.com/t/automate-macro-testing-before-model-run/13930 "2024-06-24T10:21:48Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Rainier](https://avatars.discourse-cdn.com/v4/letter/r/e0b2c6/32.png) [@Rainier](https://discourse.getdbt.com/u/Rainier)\
**Post date:** [June 24, 2024, 10:21am UTC](https://discourse.getdbt.com/t/automate-macro-testing-before-model-run/13930/1 "2024-06-24T10:21:48Z")

</div>

## Automating Macro Testing in dbt

I’m working with two interconnected models where the execution of the second model depends on the successful completion of the first. To ensure data integrity, I’ve set up tests using macros within my dbt project. These tests are specified in the `schema.yml` file associated with each model.

Here’s a snippet of my `schema.yml`:

```auto
version: 2
 
models:
  - name: joined_data_cte
    columns:
      - name: VAP_SIGMA_CM
        tests:
          - values_less_than_neg_6
      # Additional columns and tests...

  - name: dev_fatman_dbt
    depends_on:
      - model: joined_data_cte

```

Despite setting up post-hooks in the configuration file, the tests aren’t running as intended after the completion of the first model. I’ve also experimented with consolidating all tests into a single macro and invoking it as a hook within the configuration of the first model, but without success.

I’m seeking assistance in troubleshooting this issue. If anyone has experience automating dbt tests or has encountered similar challenges, I’d greatly appreciate your insights and guidance. Thank you in advance for your help!
