# dbt unit tests, written by AI in VS Code

> Click plus next to Unit Tests in the Documentation Editor and Altimate Code proposes dbt unit test scenarios with full YAML, added only after you approve.

Source: https://altimate.ai/product-highlights/generate-dbt-unit-tests-in-the-documentation-editor

[.md](https://altimate.ai/product-highlights/generate-dbt-unit-tests-in-the-documentation-editor.md) 

Copy as MD

PowerUser Plugin for dbt

## Generate dbt Unit Tests in the Documentation Editor, Next to Your Docs and Data Tests

Click plus next to Unit Tests in the Documentation Editor and Altimate Code proposes dbt unit test scenarios with full YAML, added only after you approve.

Atharva ShahOct 16, 20263 min read

 Generate dbt unit tests in the Documentation Editor, next to your docs and data tests 

TL;DR

-   **What it is.** The Documentation Editor in the PowerUser Plugin for dbt, where you write docs, add data tests and now add model-level unit tests. The AI drafts need a free Altimate API key.
-   **Who it is for.** Analytics engineers who know a model needs tests and docs, and never find the hour to write the YAML.
-   **What you get.** Unit test scenarios with full input and expected-output YAML, written to your schema file only after you pick one.

Data tests check the rows in a table. They catch a null or a duplicate key after the model builds. They cannot prove that the logic behind the table is right. A dbt unit test does that. You give the model fixed input rows and state the exact output you expect.

| | Data test | Unit test |
| --- | --- | --- |
| Runs | After the model builds | Before the model builds |
| Reads | The rows in the table | Fixed input rows you write |
| Finds | Bad data, such as a null key | Wrong logic, such as a split payment summed twice |
| Example | `unique`, `not_null` | `test_orders_split_payment` |

## Open the Documentation Editor From the PowerUser Icon

With a model open, click the PowerUser Plugin for dbt icon in the side bar and open the Documentation Editor. It holds the model description, the model's data tests and unit tests, and one row per column. Generate descriptions for the model or for a single column. Then rewrite any description with Regenerate, Make it shorter, Make it longer, Make it fun or Generate for business user.

 The Regenerate Documentation picker for column customer\_id, offering Regenerate, Make it shorter, Make it longer, Make it fun and Generate for business user, above the Documentation Editor row for customer\_id with Data Tests not\_null, relationships, accepted\_values, unique and Custom Test. 

## Add Data Tests in a Few Clicks

Click the plus sign next to a column's data tests to add a generic test. The editor offers four:

-   `unique`, so no value repeats in the column.
-   `not_null`, so every row has a value.
-   `accepted_values`, so the column holds only the values you type.
-   `relationships`, so each value exists in another model.

For accepted values, type the allowed values and click Add. For any other rule, click Custom Test. An Altimate Code session writes the test and adds nothing until you approve it. The [tests guide](https://help.altimate.ai/dbt-power-user/test/writetests/) lists every generic test the editor supports.

## Let Altimate Code Propose Unit Test Scenarios

Click the plus sign next to **Unit Tests** at model level. Altimate Code reads the model and proposes scenarios, each with the full YAML for its inputs and expected output. On the `orders` model it proposed four:

1.  A single payment method.
2.  A split payment across two methods on one order.
3.  Several orders, to check that grouping keeps them apart.
4.  An order with no payments, the LEFT JOIN edge case.

 The Altimate Code chat titled Unit tests proposal for orders dbt model, listing four proposed unit test scenarios, above the Documentation Editor for Model: orders with its Data Tests and Unit Tests rows. 

You review the YAML and reply with the scenario you want. Altimate Code adds `test_orders_split_payment` to `models/schema.yml`, then runs the models to confirm the test passes. From then on, dbt checks that logic on every run. The unit test then fails if someone changes how the model sums payments. It fails before the change reaches a dashboard.

 The chat confirms Adding the split payment unit test to models/schema.yml, the Unit Tests row now shows test\_orders\_split\_payment, and a side panel shows its YAML with two payment rows for order 2, credit\_card 10 and gift\_card 5. 

Spotlight 3 video, dbt docs, data tests and unit tests in one editor

Need descriptions for every column at once? Use [bulk documentation generation](https://help.altimate.ai/dbt-power-user/document/generatedoc/).

### Install the dbt VS Code extension

[Install from Marketplace](https://marketplace.visualstudio.com/items?itemName=innoverio.vscode-dbt-power-user) [Book a 30-min demo →](https://calendly.com/d/ctnv-rbc-yr3/altimate-ai-overview) [Read the docs →](https://help.altimate.ai/dbt-power-user/) 

## Frequently Asked Questions

What is the difference between a dbt data test and a dbt unit test?

A data test runs after the model builds and checks the rows in the table, such as no nulls or no duplicate keys. A unit test runs on fixed input rows you provide and compares the model's output to the rows you expect. Data tests find bad data. Unit tests find wrong logic.

Which dbt version supports unit tests?

dbt added unit tests in version 1.8. The Documentation Editor writes them as standard dbt YAML under the model in your schema file. They run with dbt build like any test you write by hand.

Does Altimate Code write the unit test without asking?

No. It proposes scenarios with full YAML and waits for you to choose one. It edits your schema file only after your reply, then runs the models to confirm the new test passes.

Can I add a test the generic list does not cover?

Yes. Click Custom Test on a column and describe the rule you want in plain English. An Altimate Code session writes the test for you and adds nothing to your schema file until you approve it.

How do I rewrite a description for business users?

Click the generate icon on a description and pick Generate for business user. The other options are Regenerate, Make it shorter, Make it longer and Make it fun.

Do the AI features need an API key?

Yes. Writing descriptions and tests by hand works in the free extension. Generating documentation and tests with AI needs a free Altimate API key, which you add in the extension settings.

Does this work in Cursor?

Yes. The PowerUser Plugin for dbt installs in Cursor from Open VSX, and the Documentation Editor works the same way there as in VS Code.

On this page

-   Open the Documentation Editor From the PowerUser Icon 
-   Add Data Tests in a Few Clicks 
-   Let Altimate Code Propose Unit Test Scenarios 

## Related Resources

PowerUser Plugin for dbt Profile a dbt Query in One Click and Get Its Bugs, Anti-Patterns and Fixes Ranked

https://altimate.ai/product-highlights/profile-a-slow-dbt-query-execution-plan

PowerUser Plugin for dbt Ask Altimate Code About a dbt Model Straight from the Lineage Graph

https://altimate.ai/product-highlights/ask-ai-about-dbt-lineage-in-vs-code

PowerUser Plugin for dbt Profile Every CTE in a dbt Model to Find the Join That Inflates Your Rows

https://altimate.ai/product-highlights/debug-a-dbt-model-by-profiling-each-cte

Help Doc Generate and Edit Tests

https://help.altimate.ai/dbt-power-user/test/writetests/

## Install the dbt VS Code Extension. Free to Start.

Power User for dbt is an open source VS Code extension that adds column lineage, autocomplete, AI docs, query previews and health checks to your dbt project.

[Install from Marketplace](https://marketplace.visualstudio.com/items?itemName=innoverio.vscode-dbt-power-user) [Book a Demo](https://calendly.com/d/ctnv-rbc-yr3/altimate-ai-overview) 

[Read the docs →](https://help.altimate.ai/dbt-power-user/) 

 The Altimate platform: team spend by warehouse, dbt column lineage and an Altimate Code session recap
