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.
Works with
AI-first code editor with Composer
Before installing skills in Cursor, ensure your development environment meets these requirements:
node --versionadding-dbt-unit-testExecute the skills CLI command in your project's root directory to begin installation:
Fetches adding-dbt-unit-test from dbt-labs/dbt-agent-skills and configures it for Cursor.
The CLI shows a list of agents. Use arrow keys and space to select Cursor:
Confirm successful installation by checking the skill directory location:
Restart Cursor to activate adding-dbt-unit-test. Access via /adding-dbt-unit-test in your agent's command palette.
We perform automated surface-level scans (Gen AI Scanner, Socket, Snyk) during installation. These checks detect common vulnerabilities but do not guarantee complete security. Always review skill source code and verify the publisher's reputation before production use.
Skills execute code in your environment. Always review source, verify the publisher, and test in isolation before production.
Submit your Claude Code skill and start earning
Automate repetitive workflows and reduce manual effort
Example
Generate reports, summarize documents, draft communications
Save 3-5 hours per week on routine tasks
Learn new skills, understand complex topics, get expert guidance
Example
Explain concepts, provide examples, suggest learning resources
Accelerate learning and skill development by 2x
Enhance output quality through reviews, suggestions, and refinements
Example
Review drafts, suggest improvements, catch errors
Improve work quality by 30-40% with less effort
0
total installs
0
this week
362
GitHub stars
0
upvotes
Run in your terminal
0
installs
0
this week
362
stars
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.
You should unit test a model:
More examples:
case when statements when there are many whensCases we don't recommend creating unit tests for:
min(), etc.dbt unit test uses a trio of the model, given inputs, and expected outputs (Model-Inputs-Outputs):
model - when building this modelgiven inputs - given a set of source, seeds, and models as preconditionsexpect output - then expect this row content of the model as a postconditionSelf explanatory -- the title says it all!
format if different than the default (YAML dict).
formats for unit tests" section below to determine which format to use.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
format if different than the default (YAML dict).
formats for unit tests" section below to determine which format to use.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}
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
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.
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
materialized view materialization.expect output for final state of the database table after inserting/merging for incremental models.expect output for what will be merged/inserted for incremental models.model-paths directory (models/ by default)test-paths directory (tests/fixtures by default)ref or source model references in the unit test configuration as inputs to avoid "node not found" errors during compilation.format: sql for the ephemeral model input.join logicUse inputs in your unit tests to reference a specific model or source for the test:
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')rows: []
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: [email protected], email_top_level_domain: example.com}
- {email: [email protected], 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: []
...
formats for unit testsdbt supports three formats for mock data within unit tests:
dict (default): Inline YAML dictionary values.csv: Inline CSV values or a CSV file.sql: Inline SQL query or a SQL file.To see examples of each of the formats, see Prerequisites Time Estimate 15-45 minutes depending on use case complexity Steps Common Pitfalls ✓ Do ✗ Don't 💡 Pro Tips ✓ Use when Use when skill capabilities match your task, clear ROI on time saved, and you can validate outputs. Best for repetitive tasks, learning, and quality improvement. ✗ Avoid when Avoid when task requires deep expertise you can't validate, involves sensitive decisions, or when learning process is more valuable than speed of completion. cexll/myclaude github/awesome-copilot github/awesome-copilot aj-geddes/useful-ai-prompts microsoft/playwright-cli github/awesome-copilot Keeps context tight: adding-dbt-unit-test is the kind of skill you can hand to a new teammate without a long onboarding doc. Registry listing for adding-dbt-unit-test matched our evaluation — installs cleanly and behaves as described in the markdown. Solid pick for teams standardizing on skills: adding-dbt-unit-test is focused, and the summary matches what you get after install. Registry listing for adding-dbt-unit-test matched our evaluation — installs cleanly and behaves as described in the markdown. Keeps context tight: adding-dbt-unit-test is the kind of skill you can hand to a new teammate without a long onboarding doc. I recommend adding-dbt-unit-test for anyone iterating fast on agent tooling; clear intent and a small, reviewable surface area. adding-dbt-unit-test is among the better-maintained entries we tried; worth keeping pinned for repeat workflows. Useful defaults in adding-dbt-unit-test — fewer surprises than typical one-off scripts, and it plays nicely with `npx skills` flows. adding-dbt-unit-test is among the better-maintained entries we tried; worth keeping pinned for repeat workflows. adding-dbt-unit-test fits our agent workflows well — practical, well scoped, and easy to wire into existing repos. showing 1-10 of 38Implementation Guide
Best Practices
When to Use This
Learning Path
Related Skills
test-cases
21Testingtag: testpolyglot-test-agent
11Testingtag: testplaywright-generate-test
4Testingtag: testaccessibility-testing
6Testingsame categoryplaywright-cli
6Testingsame categoryspring-boot-testing
6Testingsame categoryReviews
4.5★★★★★38 reviewsLLiam Gupta★★★★★Dec 28, 2024SShikha Mishra★★★★★Dec 12, 2024YYash Thakker★★★★★Nov 19, 2024OOmar Wang★★★★★Nov 19, 2024RRahul Santra★★★★★Nov 3, 2024PPratham Ware★★★★★Oct 22, 2024DDhruvi Jain★★★★★Oct 10, 2024OOlivia Nasser★★★★★Oct 10, 2024HHarper Wang★★★★★Sep 21, 2024OOshnikdeep★★★★★Sep 13, 20241 / 4Discussion
Comments — not star reviews