Token导航 LogoToken导航

Agent Skill · 待分类

adding-dbt-unit-test(添加 dbt 单元测试)

用于辅助测试设计、自动化测试、用例整理和回归验证。它适合让 Agent 编写单元测试、端到端测试、测试计划或根据失败日志定位问题。使用时需要确认项目测试框架、运行命令和夹具数据,避免为了通过测试而改坏真实逻辑;涉及浏览器或外部服务时,应区分本地模拟、测试环境和生产环境。

adding-dbt-unit-test 是待分类类 Agent Skill,可用宿主为 Codex、Claude、Cursor、Gemini CLI,通过GitHub 仓库获取,权限为接触敏感数据;许可证信息还不明确,第三方扫描已通过,按安装量在待分类类的 11,209 个 Skill 里排第 961。

总安装 6,139周安装 261GitHub Stars 448下载 2,151核验 2026-05-01

安装说明

本站只整理中文说明,不托管安装包,也不代用户安装。
GitHub
许可证
unknown

安装方式

通过对话安装

复制提示词发给支持本地命令或 Skills 的 AI 助手,先确认命令和权限,再让它执行。

请帮我安装这个 Agent Skill:adding-dbt-unit-test(添加 dbt 单元测试)
来源仓库:https://github.com/dbt-labs/dbt-agent-skills
仓库路径:skills/adding-dbt-unit-test
安装命令:
npx skills add https://github.com/dbt-labs/dbt-agent-skills --skill adding-dbt-unit-test
安装前请先检查当前环境是否支持对应 CLI,并向我确认将要执行的命令、安装目录、联网范围和文件读写权限;确认后再执行。

命令行安装

复制命令到本机终端执行。该命令会通过 npx skills 从第三方来源获取 Skill;本站只展示命令,不托管安装包,也不自动执行。

skills.shnpx skills
npx skills add https://github.com/dbt-labs/dbt-agent-skills --skill adding-dbt-unit-test

这个 Skill 是做什么的

这个 Skill 的分类还没最终确定,用法以来源仓库的说明为准。

adding-dbt-unit-test 用于为 dbt 模型编写单元测试,验证数据逻辑和业务规则正确性。适用于数据仓库项目中需要测试增量模型、特殊依赖或版本化 SQL 模型的场景。支持多种测试格式(dict、csv、sql),提供类型处理和平台特定注意事项,如 BigQuery 数据类型。

使用前需确认项目测试框架配置和运行命令,避免因测试覆盖而误改核心逻辑,建议结合 CI 流程执行。适用宿主包括 Codex、Claude、Cursor、Gemini CLI,接入前应确认版本、权限和运行环境要求。

来源仓库内路径:skills/adding-dbt-unit-test

上手步骤

4 步
  1. 1

    确认自己的宿主工具

    公开资料标注支持 Codex、Claude、Cursor、Gemini CLI;先确认自己用的是其中之一,再按对应工具的 Skills 目录放置。

  2. 2

    拿到安装命令

    可以直接复制的命令是 npx skills add https://github.com/dbt-labs/dbt-agent-skills --skill adding-dbt-u…;命令里的占位符换成自己的路径或密钥再执行。

  3. 3

    安装后重启宿主

    命令执行完要完全退出宿主工具再打开,让新装的 Skill 被重新扫描到,否则列表里可能看不到。

  4. 4

    按最小权限试用

    它需要接触敏感数据,先在测试目录或测试账号里跑,确认没问题再放到正式项目。

常见问题

6 条

adding-dbt-unit-test 怎么安装?

在终端执行 npx skills add https://github.com/dbt-labs/dbt-agent-skills --skill adding-dbt-unit-test。装完完全退出宿主工具再打开,让它重新扫描本地 Skill。

adding-dbt-unit-test 支持哪些 AI 工具?

公开资料标注支持 Codex、Claude、Cursor、Gemini CLI。其他工具只要能读取本地 Skill 目录,一般也能手动放进去,但要自己确认触发方式是否一致。

adding-dbt-unit-test 需要什么权限?

权限级别是接触敏感数据。该 Skill 可能接触密钥、Token、环境变量或敏感配置,应进入高风险复核队列,默认不自动发布。

adding-dbt-unit-test 是免费的吗?

公开资料没有标注明确许可证,收费和商用限制都无法确认。正式使用前请到来源仓库核对授权说明。

adding-dbt-unit-test 用的人多吗?

公开数据是累计安装 6,139 次,近一周安装 261 次,下载 2,151 次,GitHub 448 星。这些数字来自第三方目录统计,只能当作热度参考,不代表质量或安全性。

adding-dbt-unit-test 安全吗?

第三方扫描结果为通过,但这只覆盖已知的静态检查项,不能替代自己读一遍源码和安装命令。

值得选的地方和要先想清楚的地方

值得选的地方

  • 同时适配 4 种工具,换客户端不用重新找替代品。
  • 第三方扫描已通过,常见的高风险行为没有命中。

先想清楚的地方

  • 需要接触敏感数据,装到常用环境前要先评估影响面。
  • 许可证没有明确标注,能不能商用、能不能再分发都不确定。
  • 第三方目录整理,版本更新和行为细节以来源仓库为准。

适不适合你

更适合

  • 已经在用 Codex,想直接扩展它能力的人。
  • 需要处理待分类类任务、又不想每次都手写提示词的人。

不太适合

  • 环境里有大量密钥、凭证,不方便给第三方 Skill 读取的人。
  • 需要明确授权才能用到公司项目里的场景。
  • 需要厂商级技术支持和 SLA 的生产系统。

待分类类 Skill 对比

6 个同类
Skill总安装GitHub 星权限许可证扫描
infsh-cli

infsh CLI · Codex、Claude

4,374,576382权限未标注未明确未收录
ai-video-generation

AI 视频生成 · Codex、Claude

4,313,376382调用外部服务未明确有提醒
lark-openapi-explorer

云雀 OpenAPI 浏览器 · Codex、Claude

2,064,1209,011需要联网未明确有提醒
lark-workflow-standup-report

Lark 工作流程站立报告 · Codex、Claude

2,041,6328,978需要联网未明确通过
use-my-browser

使用我的浏览器 · Codex、Claude

1,848,49140操作浏览器未明确未通过
adding-dbt-unit-test

添加 dbt 单元测试 · 本页

6,139448接触敏感数据未明确通过

按安装量取同分类前几名;数字来自第三方目录统计,只作热度参考,不代表质量结论。

SKILL.md 原文

Add unit test for a dbt model

Additional Resources

What are unit tests in dbt

dbt unit tests validate SQL modeling logic on static inputs before materializing in production. If any unit test for a model fails, dbt will not materialize that model.

When to use

You should unit test a model:

  • Adding Model-Input-Output scenarios for the intended functionality of the model as well as edge cases to prevent regressions if the model logic is changed at a later date.
  • Verifying that a bug fix solves a bug report for an existing dbt model.

More examples:

  • When your SQL contains complex logic:

- Regex - Date math - Window functions - case when statements when there are many whens - Truncation - Complex joins (multiple joins, self-joins, or joins with non-trivial conditions)

  • When you're writing custom logic to process input data, similar to creating a function.
  • Logic for which you had bugs reported before.
  • Edge cases not yet seen in your actual data that you want to be confident you are handling properly.
  • Prior to refactoring the transformation logic (especially if the refactor is significant).
  • Models with high "criticality" (public, contracted models or models directly upstream of an exposure).

When not to use

Cases we don't recommend creating unit tests for:

  • Built-in functions that are tested extensively by the warehouse provider. If an unexpected issue arises, it's more likely a result of issues in the underlying data rather than the function itself. Therefore, fixture data in the unit test won't provide valuable information.

- common SQL spec functions like min(), etc.

General format

dbt unit test uses a trio of the model, given inputs, and expected outputs (Model-Inputs-Outputs):

  1. model - when building this model
  2. given inputs - given a set of source, seeds, and models as preconditions
  3. expect output - then expect this row content of the model as a postcondition

Workflow

1. Choose the model to test

Self explanatory -- the title says it all!

2. Mock the inputs

  • Create an input for each of the nodes the model depends on.
  • Specify the mock data it should use.
  • Specify the format if different than the default (YAML dict).

- See the "Data formats for unit tests" section below to determine which format to use.

  • The mock data only needs include the subset of columns used within this test case.

Tip: Use dbt show to explore existing data from upstream models or sources. This helps you understand realistic input structures. However, always sanitize the sample data to remove any sensitive or PII information before using it in your unit test fixtures.

# Preview upstream model data
dbt show --select upstream_model --limit 5

3. Mock the output

  • Specify the data that you expect the model to create given those inputs.
  • Specify the format if different than the default (YAML dict).

- See the "Data formats for unit tests" section below to determine which format to use.

  • The mock data only needs include the subset of columns used within this test case.

4. Ensure upstream models exist before running

Unit tests require direct parent models to exist in the warehouse. Before running unit tests standalone (dbt test), verify that upstream models already exist first:

# Check if upstream models exist in the warehouse
dbt list --select +my_model --exclude my_model --resource-type model
# Then verify the tables/views actually exist in the warehouse via dbt show or your SQL client
dbt show --select upstream_model --limit 1

If upstream models do not exist, or exist but have been modified and not yet refreshed, build them using --empty to create schema-only versions:

# Build upstream models cheaply (schema only, no data read)
dbt run --select +my_model --exclude my_model --empty
Warning: --empty overwrites existing models with schema-only (zero-row) versions. Only use it when models don't exist yet, or when schema changes need to be applied. Do not use it if upstream models contain data you want to preserve — it will wipe that data.

Skip this step if using dbt build --select my_model (recommended) — it handles the full pipeline including unit tests.

Minimal unit test

Suppose you have this model:

-- models/hello_world.sql

select 'world' as hello

Minimal unit test for that model:

# models/_properties.yml

unit_tests:
  - name: test_hello_world

    # Always only one transformation to test
    model: hello_world

    # No inputs needed this time!
    # Most unit tests will have inputs -- see the "real world example" section below
    given: []

    # Expected output can have zero to many rows
    expect:
      rows:
        - {hello: world}

Executing unit tests

Run the unit tests, build the model, and run the data tests for the hello_world model:

dbt build --select hello_world

This saves on warehouse spend as the model will only be materialized and move on to the data tests if the unit tests pass successfully.

Or only run the unit tests without building the model or running the data tests:

dbt test --select "hello_world,test_type:unit"

Or choose a specific unit test by name:

dbt test --select test_is_valid_email_address

Excluding unit tests from production builds

dbt Labs strongly recommends only running unit tests in development or CI environments. Since the inputs of the unit tests are static, there's no need to use additional compute cycles running them in production. Use them when doing development for a test-driven approach and CI to ensure changes don't break them.

Use the --resource-type flag --exclude-resource-type or the DBT_EXCLUDE_RESOURCE_TYPES environment variable to exclude unit tests from your production builds and save compute.

More realistic example

unit_tests:

  - name: test_order_items_count_drink_items_with_zero_drinks
    description: >
      Scenario: Order without any drinks
        When the `order_items_summary` table is built
        Given an order with nothing but 1 food item
        Then the count of drink items is 0

    # Model
    model: order_items_summary

    # Inputs
    given:
      - input: ref('order_items')
        rows:
          - {
              order_id: 76,
              order_item_id: 3,
              is_drink_item: false,
            }
      - input: ref('stg_orders')
        rows:
          - { order_id: 76 }

    # Output
    expect:
      rows:
        - {
            order_id: 76,
            count_drink_items: 0,
          }

For more examples of unit tests, see references/examples.md

Supported and unsupported scenarios

  • dbt only supports unit testing SQL models.

- Unit testing Python models is not supported. - Unit testing non-model nodes like snapshots, seeds, sources, analyses, etc. is not supported.

  • dbt only supports adding unit tests to models in your *current* project.

- Unit testing cross-project models or models imported from a package is not supported.

  • dbt *does not* support unit testing models that use the materialized view materialization.
  • dbt *does not* support unit testing models that use recursive SQL.
  • dbt *does not* support unit testing models that use introspective queries.
  • dbt *does not* support an expect output for final state of the database table after inserting/merging for incremental models.
  • dbt *does* support an expect output for what will be merged/inserted for incremental models.

Handy to know

  • Unit tests must be defined in a YAML file in your model-paths directory (models/ by default)
  • Fixture files for unit tests must be defined in a SQL or CSV file in your test-paths directory (tests/fixtures by default)
  • Include all ref or source model references in the unit test configuration as inputs to avoid "node not found" errors during compilation.
  • If your model has multiple versions, by default the unit test will run on *all* versions of your model.
  • If you want to unit test a model that depends on an ephemeral model, you must use format: sql for the ephemeral model input.
  • Table names within the model must be aliased in order to unit test join logic

YAML for specifying unit tests

  • For all the required and optional keys in the YAML definition of unit tests, see references/spec.md

Inputs for unit tests

Use inputs in your unit tests to reference a specific model or source for the test:

  • For input:, use a string that represents a ref or source call:

- ref('my_model') or ref('my_model', v='2') or ref('dougs_project', 'users') - source('source_schema', 'source_name')

  • For seed inputs:

- If you do not supply an input for a seed, we will use the seed's CSV file *as* the input. - If you do supply an input for a seed, we will use that input instead.

  • Use “empty” inputs by setting rows to an empty list rows: []

- This is useful if the model has a ref or source dependency, but its values are irrelevant to this particular unit test. Just beware if the model has a join on that input that would cause rows to drop out!

models/schema.yml

unit_tests:
  - name: test_is_valid_email_address  # this is the unique name of the test
    model: dim_customers  # name of the model I'm unit testing
    given:  # the mock data for your inputs
      - input: ref('stg_customers')
        rows:
         - {email: cool@example.com,     email_top_level_domain: example.com}
         - {email: cool@unknown.com,     email_top_level_domain: unknown.com}
         - {email: badgmail.com,         email_top_level_domain: gmail.com}
         - {email: missingdot@gmailcom,  email_top_level_domain: gmail.com}
      - input: ref('top_level_email_domains')
        rows:
         - {tld: example.com}
         - {tld: gmail.com}
      - input: ref('irrelevant_dependency')  # dependency that we need to acknowlege, but does not need any data
        rows: []
...

Data formats for unit tests

dict is the default format — always start here

Unless you have a specific reason to use another format, use dict (inline YAML). It is the default when format: is omitted.

given:
  - input: ref('orders')
    # no format: key needed — dict is the default
    rows:
      - {order_id: 1, status: completed, amount: 100}
      - {order_id: 2, status: pending, amount: 50}

How to choose the format

Use dict (default)Use sqlUse csv
Everything else — this is the starting pointModel depends on an ephemeral modelUsing an external fixture file
Column data type not supported by dict/csvColumn data type not supported by dict
External fixture file with unsupported types

Critical sql note: sql format requires specifying ALL columns in the mock data. dict and csv only require the columns relevant to the test — much more concise.

Critical sql requirement: If any of your model's ref() or source() inputs are ephemeral models, you must use sql format for those inputs. dict and csv will fail.

dbt supports three formats for mock data within unit tests:

  1. dict (default): Inline YAML dictionary values.
  2. csv: Inline CSV values or a CSV file.
  3. sql: Inline SQL query or a SQL file.

To see examples of each of the formats, see references/examples.md

Notes:

  • For the sql format you must supply mock data for *all columns* whereas dict and csv may supply only a subset.
  • Only the sql format allows you to unit test a model that depends on an ephemeral model -- dict and csv can't be used in that case.
  • There are no formats that support Jinja.

Fixture files

The dict format only supports inline YAML mock data, but you can also use csv or sql either inline or in a separate fixture file. Store your fixture files in a fixtures subdirectory in any of your test-paths. For example, tests/fixtures/my_unit_test_fixture.sql.

When using the dict or csv format, you only have to define the mock data for the columns relevant to you. This enables you to write succinct and *specific* unit tests. For the sql format *all* columns need to be defined.

Special cases

Platform/adapter-specific caveats

There are platform-specific details required if implementing on (Redshift, BigQuery, etc). Read the caveats file for your database (if it exists):

Platform/adapter-specific data types

Unit tests are designed to test for the expected *values*, not for the data types themselves. dbt takes the value you provide and attempts to cast it to the data type as inferred from the input and output models.

How you specify input and expected values in your unit test YAML definitions are largely consistent across data warehouses, with some variation for more complex data types.

Read the data types file for your database:

Disabling a unit test

By default, all specified unit tests are enabled and will be included according to the --select flag.

To disable a unit test from being executed, set:

    config:
      enabled: false

This is helpful if a unit test is incorrectly failing and it needs to be disabled until it is fixed.

When a unit test fails

When a unit test fails, there will be a log message of "actual differs from expected", and it will show a "data diff" between the two:

actual differs from expected:

@@ ,email           ,is_valid_email_address
→  ,cool@example.com,True→False
   ,cool@unknown.com,False

There are two main possibilities when a unit test fails:

  1. There was an error in the way the unit test was constructed (false positive)
  2. There is an bug is the model (true positive)

It takes expert judgement to determine one from the other.

The --empty flag

The direct parents of the model that you’re unit testing need to exist in the warehouse before you can execute the unit test. The run and build commands supports the --empty flag for building schema-only dry runs. The --empty flag limits the refs and sources to zero rows. dbt will still execute the model SQL against the target data warehouse but will avoid expensive reads of input data. This validates dependencies and ensures your models will build properly.

Use the --empty flag to build an empty version of the models to save warehouse spend.

dbt run --select "stg_customers top_level_email_domains" --empty

Common Mistakes

MistakeFix
Testing simple SQL using built-in functionsOnly unit test complex logic: regex, date math, window functions, multi-condition case statements
Mocking all columns in input dataOnly include columns relevant to the test case
Using sql format when dict worksPrefer dict (most readable), fall back to csv or sql only when needed
Missing input for a ref or sourceInclude all model dependencies to avoid "node not found" errors
Testing Python models or snapshotsUnit tests only support SQL models

平台分布

Codex

37.7%
按下载量换算811

Claude

27.96%
按下载量换算601

Cursor

18.81%
按下载量换算405

Gemini CLI

9.65%
按下载量换算208

安全审计

Gen Agent Trust Hub

通过

Socket

通过

Snyk

通过

权限和风险

接触敏感数据

该 Skill 可能接触密钥、Token、环境变量或敏感配置,应进入高风险复核队列,默认不自动发布。

安装前确认

本站仅展示第三方公开信息,不托管安装包,不提供自动安装或运行环境。安装前应自行审查源码、依赖和命令行为。目前只有一个公开来源,建议同时核对源仓库。

继续浏览同类 Skills