---
name: step-07-tests
description: Scaffold tests via MCP for all modified layers
model: opus
prev_step: steps/step-06-resolve.md
next_step: steps/step-08-run-tests.md
---

# Step 7: Tests (if -t)

**Goal:** Scaffold comprehensive tests using MCP tools. Target: >= 80% coverage.

---

## 1. Ensure Test Project Exists

```bash
# Check for existing test project
TEST_PROJECT=$(find tests/ -name "*.Tests.Unit.csproj" 2>/dev/null | head -1)

if [ -z "$TEST_PROJECT" ]; then
  # Create test project
  PROJECT_NAME=$(basename *.sln .sln)
  dotnet new xunit -n "${PROJECT_NAME}.Tests.Unit" -o "tests/${PROJECT_NAME}.Tests.Unit"
  dotnet add "tests/${PROJECT_NAME}.Tests.Unit" package Moq
  dotnet add "tests/${PROJECT_NAME}.Tests.Unit" package FluentAssertions
  for proj in src/*/*.csproj; do
    dotnet add "tests/${PROJECT_NAME}.Tests.Unit" reference "$proj"
  done
  dotnet sln add "tests/${PROJECT_NAME}.Tests.Unit/${PROJECT_NAME}.Tests.Unit.csproj"
fi
```

---

## 2. Scaffold Tests via MCP

For each layer that was modified:

### Domain Tests
```
Call: mcp__smartstack__scaffold_tests
  target_layer: "domain"
  module: "{module_code}"
  test_type: "unit"

Tests: entity creation, validation, domain events, value objects
```

### Application Tests
```
Call: mcp__smartstack__scaffold_tests
  target_layer: "application"
  module: "{module_code}"
  test_type: "unit"

Tests: service logic, CQRS handlers, FluentValidation
```

### API Tests
```
Call: mcp__smartstack__scaffold_tests
  target_layer: "api"
  module: "{module_code}"
  test_type: "integration"

Tests: controller endpoints, authorization, response DTOs
```

### Security Tests
```
Call: mcp__smartstack__scaffold_tests
  module: "{module_code}"
  test_type: "security"

Tests: RequirePermission enforcement, multi-tenant isolation
```

---

## 3. Suggest Additional Scenarios

```
Call: mcp__smartstack__suggest_test_scenarios
  module: "{module_code}"

Review suggestions and add relevant test cases.
```

---

## 4. Analyze Coverage

```
Call: mcp__smartstack__analyze_test_coverage
  module: "{module_code}"

Target: >= 80% coverage
If under 80%: identify uncovered paths, scaffold additional tests
```

---

## 5. Test Summary

```
**APEX SmartStack - Tests Scaffolded**

| Layer | Tests Created | Coverage |
|-------|--------------|----------|
| Domain | {count} | {%} |
| Application | {count} | {%} |
| API | {count} | {%} |
| Security | {count} | {%} |

**Total tests:** {count}
**Estimated coverage:** {%}
```

---

## 6. Save Output (if save_mode)

Write to `{output_dir}/07-tests.md` with test scaffolding results.

---

## NEXT STEP

Load `steps/step-08-run-tests.md`
