dbt-unit-tests

Generate dbt unit tests with mock inputs and expected outputs for SQL models.

803|134|Updated Feb 27, 2026
One-click install
npx skills add https://github.com/AltimateAI/altimate-code --skill dbt-unit-tests
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: dbt-unit-tests
Source: https://github.com/AltimateAI/altimate-code/tree/main/.opencode/skills/dbt-unit-tests
Command: npx skills add https://github.com/AltimateAI/altimate-code --skill dbt-unit-tests

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve?

Writing dbt unit tests by hand is slow and error-prone: you must enumerate every upstream ref and source, build type-correct mock data, and compute expected outputs for CASE/WHEN branches, JOINs, window functions, and NULL handling. This Skill automates that analysis and assembles complete, validated unit test YAML for any dbt model.

Core Features & Use Cases

  • Automated test generation: Parses the dbt manifest to find all upstream dependencies, then generates complete unit test YAML with mock inputs and expected outputs via the dbt_unit_test_gen tool.
  • Edge-case coverage: Enforces mock rows that exercise failure modes of every SQL construct — LEFT JOIN misses, division by zero, NULL handling in COALESCE, window function boundaries, and incremental merge keys.
  • Incremental model testing: Tests both full-refresh and incremental code paths using is_incremental overrides and mocked this table state.
  • Use Case: A data engineer asks to "add unit tests to fct_orders". The Skill compiles the model, reads its SQL, generates tests covering happy path, NULL handling, and boundary values, runs altimate-dbt test to validate, and writes the YAML to the project's schema file.

Quick Start

Ask the agent to generate unit tests for a specific dbt model, for example: generate unit tests for the fct_orders model covering NULL handling and edge cases.

Frequently Asked Questions about dbt-unit-tests

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I generate unit tests for a dbt model automatically?

Ask the agent to generate unit tests for a model name. The Skill compiles the model, parses the manifest for all upstream refs and sources, generates mock inputs and expected outputs with dbt_unit_test_gen, then validates by running altimate-dbt test before writing the YAML.

How to test incremental dbt models with unit tests?

Set overrides.macros.is_incremental to true and mock the existing target table using the `this` input. Test both the full-refresh path and the incremental path, including new rows, updated rows matching the merge key, and empty source scenarios.

What dbt version supports unit tests in YAML?

dbt unit tests defined under the unit_tests key in YAML are available in dbt-core 1.8 and later. They can live in schema.yml or a dedicated _unit_tests.yml file and run with dbt test --select test_type:unit.

Why does my dbt unit test fail to compile?

Compilation failures usually come from a missing mock input for an upstream ref or source, wrong column names in mock data, or type mismatches. Use the manifest's depends_on nodes and altimate-dbt columns to get exact column names and types.

When should I use sql format instead of dict format for mock inputs?

Use format: sql with raw SELECT statements when the upstream model is ephemeral, since dict format fails silently for ephemeral dependencies. SQL format also helps for complex data types or when mock data needs SQL functions.

What is the difference between dbt unit tests and schema tests?

Unit tests mock upstream inputs and assert exact output rows for a model's transformation logic, while schema tests like not_null and unique run against real warehouse data. This Skill covers unit tests only; use dbt schema tests for generic data quality checks.