---
title: "dbt tests declared away from their models | Metacenta"
description: "Where a dbt project keeps most tests beside their models, a test declared elsewhere gets left behind when the model changes. How we measure it."
url: "https://metacenta.com/rules/test-not-beside-model"
updated: "2026-10-14"
tokens: 724
---

Maintainability · rule test-not-beside-model

# dbt tests declared away from their models

A Metacenta review checks this under the rule **Tests are declared beside the models they test**. Everything below applies whether or not you ever commission one.

## What this rule checks

This rule flags tests declared in a different directory from the model they test. It compares exact directories, so a schema file in a parent directory counts as elsewhere. When fewer than half of tests sit beside their model, we report the split once, as information.

## Why it matters

Someone editing the model cannot see its tests in the same directory. A change then ships with its assertions left behind, or with a test nobody thought to update.

## How to fix it

**Declare tests beside the models they test.** Move the test's YAML block to a schema file in the model's directory. Where we report a split, keep the majority convention and move the few that break it.

Before:

```yaml
# models/schema.yml
models:
  - name: stg_orders
    columns:
      - name: order_id
        data_tests:
          - unique
```

After:

```yaml
# models/staging/_stg_models.yml
models:
  - name: stg_orders
    columns:
      - name: order_id
        data_tests:
          - unique
```

## When it is fine to leave

Keeping every test in central files is a convention dbt permits, and a project where no test sits beside its model isn't judged. Singular tests in `tests/` belong to no single model, so they're never counted.

## What we need to check it

`manifest.json` alone. We place each test by the YAML file that declares it. Tests the manifest does not attach to a model with a known path are left out, not counted as misplaced.

## Published rules it corresponds to

**[dbt_project_evaluator](https://dbt-labs.github.io/dbt-project-evaluator/)**, rule `fct_test_directories`. Ours checks a subset of what it flags; theirs is stricter. dbt's rule flags every test not declared in its model's directory. This one first checks that the project uses that convention anywhere. It declines on a project that keeps its tests centrally, which dbt permits and many projects choose.

This means our check corresponds to their rule. It does not mean the publisher reviewed or endorses it.

[Ask about a review](https://metacenta.com/enquire?src=rule-test-not-beside-model&via=md)

## Related pages

- [Duplicate logic across dbt models](https://metacenta.com/rules/duplicate-model-logic)
- [select * in dbt models](https://metacenta.com/rules/select-star)
- [dbt models with too many CTEs](https://metacenta.com/rules/high-cte-count)
- [dbt layer naming: inconsistent model prefixes](https://metacenta.com/rules/layer-naming-mismatch)
- [A sample review, as a client reads it](https://metacenta.com/sample)
- [All published rules](https://metacenta.com/rules)
- [How a review is assessed](https://metacenta.com/standard)
