dbt-testing
БесплатноБез исполняемых скриптовНе проверенUse for any question or task about testing dbt models, including adding tests to a model's YAML and bad data such as duplicate IDs that a passing dbt build…
от testland★ 18 звёзд на GitHubОб этом скилле
dbt-testing
Overview
dbt distinguishes data tests (assertions on rows, e.g. unique / not_null)
from unit tests (logic tests on transformations); this skill targets
data tests. The YAML key was renamed from tests: to data_tests: to
disambiguate; tests: remains a back-compat alias but you cannot have both
on the same resource at the same time
(data-tests).
When to use
- The repo contains a
dbt_project.ymlor amodels/directory with.sqlfiles referencing{{ ref(...) }}/{{ source(...) }}. - The user asks about generic tests (
unique,not_null,accepted_values,relationships) - the four built-in generics shipped with dbt (data-tests). - The user mentions dbt build failures, schema drift, or wants assertions on data flowing through models.
- A CI workflow needs a quality gate that fails the pipeline when a model ships bad data.
Authoring tests
Generic tests in schema.yml
Use data_tests: (canonical) - tests: is the legacy alias and cannot
coexist with data_tests: on the same resource (data-tests).
version: 2
models:
- name: orders
columns:
- name: order_id
data_tests:
- unique
- not_null
- name: status
data_tests:
- accepted_values:
arguments:
values: ['placed', 'shipped', 'completed', 'returned']
- name: customer_id
data_tests:
- relationships:
arguments:
to: ref('customers')
field: id
The arguments: key under parameterized generics (accepted_values,
relationships) is the canonical syntax in current dbt (data-tests).
Singular tests
Singular tests live as .sql files under tests/ (or a custom test-paths
config). Each file is one select that returns failing rows - empty
result set means pass (data-tests).
tests/assert_payment_total_non_negative.sql:
-- Returns rows where the aggregated payment total is negative;
-- empty result set = test passes.
select order_id, sum(amount) as total_amount
from {{ ref('fct_payments') }}
group by 1
having sum(amount) < 0
Trap: dbt requires you to omit trailing semicolons in singular test SQL - a
;at the end can cause the test to fail spuriously (data-tests). This is unlike most SQL editors which add the semicolon by default.
Custom generic tests via macros
Reusable assertions are defined as Jinja {% test %} blocks that take
model and column arguments and return a select of failing rows
(data-tests):
{% test column_value_in_range(model, column_name, min_value, max_value) %}
select *
from {{ model }}
where {{ column_name }} < {{ min_value }}
or {{ column_name }} > {{ max_value }}
{% endtest %}
Reference once defined, then call by name in data_tests:. See
references/macros.md for the canonical macro
shapes (range checks, conditional uniqueness, recency / freshness,
external referential integrity).
What a green dbt build still lets through
Check these before calling a model "tested". Each one passes silently by design, so a model can ship bad data with every test green.
| Gap | Why the tests pass | Fix |
|---|---|---|
NULLs in an accepted_values column |
The test "validates that all of the non-null values in a column are present" in the list, so NULLs are never checked ([data-test-props][5]) |
Add not_null beside it. Map unknown codes to a value the list rejects (else status_code), not to NULL, so a new code fails a test |
| NULL foreign keys | relationships "automatically excludes NULL values from validation" ([data-test-props][5]) |
Add not_null; if NULL is legitimate (guest checkout), map it to an explicit key or flag and test that |
| A source that stopped loading | dbt build "does not include source freshness checks" ([freshness][6]) |
Configure freshness on the source and run dbt source freshness as its own CI step before dbt build |
| Late rows in an incremental model | A filter on the event's own timestamp (where viewed_at > (select max(viewed_at) from {{ this }})) drops rows that arrive late; data tests on the target never see the missing rows |
Filter on the load timestamp (or a lookback window deduplicated by unique_key) and prove it with an incremental-mode unit test (below) |
Source freshness, with both keys under config: (freshness moved to config
in v1.9, loaded_at_field in v1.10) ([freshness-config][7]):
sources:
- name: shop_raw
config:
loaded_at_field: _loaded_at
freshness:
warn_after: {count: 12, period: hour}
error_after: {count: 24, period: hour}
tables:
- name: orders
dbt source freshness # fails the job when error_after is exceeded
dbt build
Unit tests for incremental models
Unit tests check transforma
Установить dbt-testing в Claude Code и Claude Desktop
Зарегайся, чтобы установить скилл
Создай бесплатный аккаунт, чтобы открыть команду установки и сохранить скилл в библиотеку.
- Открой команду установки в одну строку
- Сохраняй скиллы в синхронизируемую библиотеку
- Уведомления, когда скиллы обновляются
Разрешённые инструменты
Инструменты, которые скиллу разрешено вызывать.
Без ограничений — скилл может использовать любой инструмент.
Вложенные файлы
FAQ
Что делает скилл dbt-testing?
Use for any question or task about testing dbt models, including adding tests to a model's YAML and bad data such as duplicate IDs that a passing dbt build missed: generic, singular and custom-macro tests, model assertions, reading failures from run_results.json and gating dbt build on the results in CI.
Как установить скилл dbt-testing?
Скопируй папку скилла в ~/.claude/skills (вкладка Claude Code выше делает это одной командой), либо поставь как плагин.
Скилл dbt-testing запускает скрипты?
Нет, скилл состоит только из инструкций (SKILL.md), без исполняемых скриптов.
Похожие скиллы
skill-creator
Create new skills, modify and improve existing skills, and measure skill performance. Use when users want to create a skill from scratch, edit, or optimize an…
от Anthropicdiscernment-nudge
After you give a substantive answer or draft that the user may act on — advice or recommendations, drafted artifacts such as goals, plans, pitches, proposals…
от Anthropicdata-consolidate
Joins the plant's scheduled exports and connector data into one working dataset — ERP items (NetSuite or Infor M3), sales orders, production work orders…
от Anthropicinspection-to-capa
Runs the quality chain end to end: writes the nonconformance against the requirement it violates, searches history at the moment of writing to say whether…
от Anthropic