# How to Add a Custom Test inside a config block of a model.

**URL:** <https://discourse.getdbt.com/t/how-to-add-a-custom-test-inside-a-config-block-of-a-model/19579>\
**Category:** Help\
**Tags:** testing, dbt-cloud\
**Created:** [June 2, 2025, 12:10am UTC](https://discourse.getdbt.com/t/how-to-add-a-custom-test-inside-a-config-block-of-a-model/19579 "2025-06-02T00:10:38Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![ShashiK](https://avatars.discourse-cdn.com/v4/letter/s/8edcca/32.png) [@ShashiK](https://discourse.getdbt.com/u/ShashiK)\
**Post date:** [June 2, 2025, 12:10am UTC](https://discourse.getdbt.com/t/how-to-add-a-custom-test-inside-a-config-block-of-a-model/19579/1 "2025-06-02T00:10:38Z")

</div>

## The problem I’m having

I have a config block inside of my model, where I want to add a test so that it can be run after the model is built.

## The context of why I’m trying to do this

I want to run certain tests during development at each model level.

## What I’ve already tried

– tests/compare\_row\_counts.sql

```auto
{% test compare_row_counts(model, prod_schema, prod_table) %}

with model_count as (
    select count(*) as cnt from {{ model }}
),

prod_count as (
    select count(*) as cnt from {{ prod_schema }}.{{ prod_table }}
),

validation as (
    select 
        model_count.cnt as model_count, 
        prod_count.cnt as prod_count
    from model_count, prod_count
)

select *
from validation
where model_count != prod_count

{% endtest %}

```

models/my\_model.sql

```auto
...
{{
    config(
        tags: ...,
        materialized: ....,
        tests: [
                {
                   'compare_row_counts': {
                            'prod_schema': 'PROD_SCH',
                            'prod_table': 'PROD_TBL',
                    }
                }
        ],
)
}}

```

When I build or test my model, it doesn’t run the tests.

Is there a way to specify tests at a model level.

Thank you.

---

<div class="post-metadata">

**Author:** ![a\_slack\_user](https://sea2.discourse-cdn.com/flex020/user_avatar/discourse.getdbt.com/a_slack_user/32/1629_2.png) [@a\_slack\_user](https://discourse.getdbt.com/u/a_slack_user)\
**Post date:** [June 2, 2025, 12:48am UTC](https://discourse.getdbt.com/t/how-to-add-a-custom-test-inside-a-config-block-of-a-model/19579/2 "2025-06-02T00:48:52Z")

</div>

Tests aren’t configured in a model’s config block typically.

Note: `@Jeremy Yeo` originally [posted this reply in Slack](https://getdbt.slack.com/archives/CBSQTAPLG/p1748825317857049?thread_ts=1748823063.742489&cid=CBSQTAPLG). It might not have transferred perfectly.

---

<div class="post-metadata">

**Author:** ![briano.bend](https://sea2.discourse-cdn.com/flex020/user_avatar/discourse.getdbt.com/briano.bend/32/4969_2.png) [@briano.bend](https://discourse.getdbt.com/u/briano.bend)\
**Post date:** [June 2, 2025, 3:23am UTC](https://discourse.getdbt.com/t/how-to-add-a-custom-test-inside-a-config-block-of-a-model/19579/3 "2025-06-02T03:23:59Z")

</div>

Typically this would be handled by adding the test to the associated .yml configuration. Additional parameters can be configured there as well. To run them immediately after the model is built use the `dbt build -s my_models` command.

---

<div class="post-metadata">

**Author:** ![ShashiK](https://avatars.discourse-cdn.com/v4/letter/s/8edcca/32.png) [@ShashiK](https://discourse.getdbt.com/u/ShashiK)\
**Post date:** [June 2, 2025, 3:49am UTC](https://discourse.getdbt.com/t/how-to-add-a-custom-test-inside-a-config-block-of-a-model/19579/4 "2025-06-02T03:49:45Z")

</div>

Thank you! I’ll try it out .

I wish we could test by adding it in config block though.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex020/uploads/getdbt/original/1X/a7a7ca1fe379aaf90952b0e13118a817babcd14f.png) [@system](https://discourse.getdbt.com/u/system)\
**Post date:** [June 9, 2025, 3:50am UTC](https://discourse.getdbt.com/t/how-to-add-a-custom-test-inside-a-config-block-of-a-model/19579/5 "2025-06-09T03:50:17Z")

</div>

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.
