testing-dbt-modelslisted
Install: claude install-skill AltimateAI/data-engineering-skills
# dbt Testing
**Every model deserves at least one test. Primary keys need unique + not_null.**
## Workflow
### 1. Study Existing Test Patterns
**CRITICAL: Match the project's existing testing style before adding new tests.**
```bash
# Find all schema.yml files with tests
find . -name "schema.yml" -exec grep -l "tests:" {} \;
# Read existing tests to learn patterns
cat models/staging/schema.yml | head -100
cat models/marts/schema.yml | head -100
# Check for custom tests or dbt packages
ls tests/
cat packages.yml 2>/dev/null
```
**Extract from existing tests:**
- YAML formatting style (indentation, spacing)
- Test coverage depth (all columns vs key columns only)
- Use of custom tests (dbt_utils, dbt_expectations, custom macros)
- Description style (brief vs detailed)
- Severity levels used (warn vs error)
### 2. Read Model SQL
```bash
cat models/<path>/<model_name>.sql
```
Identify: primary keys, foreign keys, categorical columns, date columns, business-critical fields.
### 3. Check Existing Tests for This Model
```bash
cat models/<path>/schema.yml | grep -A 50 "<model_name>"
# or
find . -name "schema.yml" -exec grep -l "<model_name>" {} \;
```
### 4. Identify Testable Columns
| Column Type | Recommended Tests |
|-------------|-------------------|
| Primary key | `unique`, `not_null` |
| Foreign key | `not_null`, `relationships` |
| Categorical | `accepted_values` (ask user for valid values) |
| Required field | `not_null` |
| Date/timestamp | `not_null` |
| Bool