Skip to content

Feature Test

Ali Sadeghi edited this page Feb 5, 2026 · 4 revisions

Feature Test

Generates comprehensive tests for a KMP feature module.

Usage:

/feature-test login

What It Does

  1. Discovery - Detects namespaces and extracts feature context (models, DataSource, Repository, ViewModel, Screen)
  2. Dependencies - Adds test dependencies to build.gradle.kts if missing
  3. Sync - Requests project sync before test generation
  4. Fixtures - Spawns test-fixtures agent (must complete first)
  5. Data Layer Tests - Spawns test-datasource + test-repository in parallel
  6. Presentation Tests - Spawns test-viewmodel + test-ui + test-integration in parallel
  7. Validation - Runs tests and generates Kover coverage report

Execution Flow

Phase 1: Discovery
    └── Extract context (YAML summaries, not full code)
         ↓
Phase 2: Sync
    └── User confirms project sync
         ↓
Phase 3: Fixtures
    └── test-fixtures (must complete first - others depend on it)
         ↓
Phase 4: Data Layer (parallel)
    ├── test-datasource
    └── test-repository
         ↓
Phase 5: Presentation (parallel)
    ├── test-viewmodel
    ├── test-ui
    └── test-integration
         ↓
Phase 6: Validation
    └── Run tests + Generate Kover coverage

Max parallel agents: 3 (memory-safe)

Spawned Agents

Agent What It Generates Dependencies
test-fixtures {Feature}Fixtures.kt + {Feature}UiFixtures.kt None (runs first)
test-datasource {Feature}RemoteDataSourceTest.kt Fixtures
test-repository {Feature}RepositoryImplTest.kt Fixtures
test-viewmodel {Feature}ViewModelTest.kt Fixtures
test-ui {Feature}ScreenTest.kt (targets ScreenRoot) UiFixtures
test-integration {Feature}IntegrationTest.kt Fixtures

Generated Files

feature/{name}/src/commonTest/kotlin/{pkg}/{name}/
├── fixtures/
│   ├── {Feature}Fixtures.kt      # Domain model factories
│   └── {Feature}UiFixtures.kt    # UiState factories (4 states)
├── data/
│   ├── datasource/
│   │   └── {Feature}RemoteDataSourceTest.kt
│   └── repository/
│       └── {Feature}RepositoryImplTest.kt
├── presentation/
│   └── {Feature}ViewModelTest.kt
└── integration/
    └── {Feature}IntegrationTest.kt

feature/{name}/src/desktopTest/kotlin/{pkg}/{name}/
└── presentation/
    └── ui/
        └── {Feature}ScreenTest.kt

Spec-Aware Testing

If .claude/docs/{featurename}/spec.md exists:

  • Extracts FR-X.Y requirement scenarios
  • Passes scenarios to ViewModel/UI agents
  • Maps test methods to spec requirements
  • Reports spec coverage percentage

ErrorConst Pattern

All test agents use standardized error handling:

  • ErrorConst.NoNetwork, ErrorConst.Unauthorized, ErrorConst.ServerUnknownError
  • JSON error responses: {"detail": "...", "code": ...}

Example Output

Test Generation Complete: login

Generated:
- LoginFixtures.kt (12 factories, 5 error constants)
- LoginUiFixtures.kt (8 UI state factories)
- LoginRemoteDataSourceTest.kt (18 tests)
- LoginRepositoryImplTest.kt (12 tests)
- LoginViewModelTest.kt (15 tests)
- LoginScreenTest.kt (10 tests)
- LoginIntegrationTest.kt (8 tests)

Total: 63 tests
Spec Coverage: 94% (17/18 scenarios covered)

Coverage Report: feature/login/build/reports/kover/html/index.html
- Line: 87% | Branch: 82%

After Completion

# Run tests manually
./gradlew :feature:{name}:desktopTest

# Run specific test class
./gradlew :feature:{name}:desktopTest --tests "*ViewModelTest"

# View coverage report
open feature/{name}/build/reports/kover/html/index.html

Key Rules

  1. Discovery extracts YAML summaries only (never full file contents)
  2. Fixtures must complete before other agents spawn
  3. UI tests target ScreenRoot, not Screen wrapper
  4. Workers do NOT re-read source files - they use pre-computed context

Back to Commands

Clone this wiki locally