LogoSkills

Test Runner Agent

This agent verifies and runs tests for Features.

Test execution and result analysis agent

Role and Responsibilities#

This agent verifies and runs tests for Features.

  1. Test Existence Check: Verify required test files exist
  2. Test Generation Delegation: Delegate to specialist agents when tests are missing
  3. Test Execution: Run Unit, BLoC, BDD Widget, and Backend integration tests
  4. Result Analysis: Analyze failed test causes
  5. Auto-Fix: Auto-fix simple test failures
  6. Verification Gate: Verify all tests pass (required gate before PR creation)

Input Parameters#

ParameterRequiredTypeDescription
feature_name✅stringFeature module name
test_types ❌ string[] unit | bloc | bdd | backend_unit | backend_integration (default: all)
auto_fix ❌ boolean Auto-fix attempt flag (default: true)
coverage ❌ boolean Generate coverage flag (default: false)
require_tests ❌ boolean Delegate creation when tests missing (default: true)

Output#

interface TestResult {
  success: boolean;
  summary: TestSummary;
  failures: TestFailure[];
  coverage?: CoverageReport;
  backend_tests?: BackendTestResult;
  fixed_tests: string[];
}

interface TestSummary {
  total: number;
  passed: number;
  failed: number;
  skipped: number;
  duration: string;
}

interface TestFailure {
  test_name: string;
  file_path: string;
  error_message: string;
  stack_trace: string;
  fixable: boolean;
}

interface CoverageReport {
  line_coverage: number;
  branch_coverage: number;
  uncovered_files: string[];
}

interface BackendTestResult {
  unit_tests: { endpoint: number; service: number; passed: number; failed: number };
  integration_tests: { total: number; passed: number; failed: number };
}

Test Execution by Type#

Unit Test (UseCase)#

# Run UseCase tests
melos exec --scope=feature_{feature_name} -- \
  flutter test test/domain/usecase/ --reporter expanded

Test Location: feature/{location}/{feature_name}/test/domain/usecase/

Test Targets:

  • get_{entity}s_usecase_test.dart
  • get_{entity}_usecase_test.dart
  • create_{entity}_usecase_test.dart
  • update_{entity}_usecase_test.dart
  • delete_{entity}_usecase_test.dart

BLoC Test#

# Run BLoC tests
melos exec --scope=feature_{feature_name} -- \
  flutter test test/presentation/bloc/ --reporter expanded

Test Location: feature/{location}/{feature_name}/test/presentation/bloc/

Test Targets:

  • {feature}_list_bloc_test.dart
  • {feature}_detail_bloc_test.dart
  • {feature}_form_bloc_test.dart

BDD Widget Test#

# Run BDD Widget tests
melos exec --scope=feature_{feature_name} -- \
  flutter test test/src/bdd/ --reporter expanded

Test Location: feature/{location}/{feature_name}/test/src/bdd/

Test Targets:

  • {feature}_list.feature + steps
  • {feature}_detail.feature + steps
  • {feature}_form.feature + steps

Execution Flow#

┌─────────────────────────────────────────────────────────┐
│  Step 0: Existing Test Verification (Baseline) ⚠ïļ        │
├─────────────────────────────────────────────────────────â”Ī
│  - Run all existing tests for related packages           │
│  - On failure → fix implementation code or existing tests first │
│  - Record baseline pass rate (for regression verification) │
└─────────────────────────────────────────────────────────┘
                          │
                          ▾
┌─────────────────────────────────────────────────────────┐
│  Step 0.5: Check Test Existence and Delegate Creation    │
├─────────────────────────────────────────────────────────â”Ī
│  [Frontend test check]                                   │
│  - UseCase test files exist? → Call unit-test-agent if missing │
│  - BLoC test files exist? → Call bloc-test-agent if missing │
│  - Widget test needed? → Call widget-test-agent if missing │
│  [Backend test check - on Backend changes]               │
│  - Endpoint tests exist? → serverpod-test-agent if missing │
│  - Service logic tests exist? → serverpod-test-agent if missing │
│  - Integration tests exist? → Call serverpod-test-agent if missing │
│  ⚠ïļ PR creation blocked if tests are not written         │
└─────────────────────────────────────────────────────────┘
                          │
                          ▾
┌─────────────────────────────────────────────────────────┐
│  Step 1: Prepare Test Environment                        │
├─────────────────────────────────────────────────────────â”Ī
│  $ melos run build                                      │
│  - Verify code generation complete                       │
│  - Verify no analysis errors                             │
└─────────────────────────────────────────────────────────┘
                          │
                          ▾
┌─────────────────────────────────────────────────────────┐
│  Step 2: Run Unit Tests                                  │
├─────────────────────────────────────────────────────────â”Ī
│  $ melos exec --scope=feature_{name} --                 │
│      flutter test test/domain/usecase/                  │
│  - Verify UseCase logic                                  │
│  - Verify Mock setup                                     │
└─────────────────────────────────────────────────────────┘
                          │
                          ▾
┌─────────────────────────────────────────────────────────┐
│  Step 3: Run BLoC Tests                                  │
├─────────────────────────────────────────────────────────â”Ī
│  $ melos exec --scope=feature_{name} --                 │
│      flutter test test/presentation/bloc/               │
│  - Verify State transitions                              │
│  - Verify Event handling                                 │
└─────────────────────────────────────────────────────────┘
                          │
                          ▾
┌─────────────────────────────────────────────────────────┐
│  Step 3.5: Run Backend Tests (on Backend changes) ⚠ïļ     │
├─────────────────────────────────────────────────────────â”Ī
│  [Unit tests]                                            │
│  $ melos exec --scope=kobic_server --                   │
│      dart test test/unit/{feature}/                     │
│  - Verify endpoint logic                                 │
│  - Verify service business logic                         │
│  [Integration tests]                                     │
│  $ melos exec --scope=kobic_server --                   │
│      dart test test/integration/{feature}/              │
│  - withServerpod-based E2E verification                  │
│  - Auth/permission verification                          │
│  - CRUD flow verification                                │
└─────────────────────────────────────────────────────────┘
                          │
                          ▾
┌─────────────────────────────────────────────────────────┐
│  Step 4: Run BDD Widget Tests                            │
├─────────────────────────────────────────────────────────â”Ī
│  $ melos exec --scope=feature_{name} --                 │
│      flutter test test/src/bdd/                         │
│  - Run Gherkin scenarios                                 │
│  - Verify UI interactions                                │
└─────────────────────────────────────────────────────────┘
                          │
                          ▾
┌─────────────────────────────────────────────────────────┐
│  Step 5: Result Analysis and Auto-Fix                    │
├─────────────────────────────────────────────────────────â”Ī
│  IF failed tests exist:                                  │
│    - Analyze failure cause                               │
│    - Determine if auto-fix is possible                   │
│    - Attempt auto-fix (up to 3 times)                    │
└─────────────────────────────────────────────────────────┘
                          │
                          ▾
┌─────────────────────────────────────────────────────────┐
│  Step 6: Verification Gate (required before PR) ⚠ïļ       │
├─────────────────────────────────────────────────────────â”Ī
│  - Frontend: UseCase test â‰Ĩ 1 passed                     │
│  - Frontend: BLoC test â‰Ĩ 1 passed                        │
│  - (On Backend changes) Backend unit tests passed        │
│  - (On Backend changes) Backend integration tests passed │
│  - Regression check: Existing test pass rate â‰Ĩ baseline  │
│  ⚠ïļ PR creation blocked on gate failure                  │
└─────────────────────────────────────────────────────────┘

Backend Test (Endpoint/Service)#

Unit Tests

# Run endpoint/service unit tests
melos exec --scope=kobic_server -- \
  dart test test/unit/{feature_name}/ --reporter expanded

Test Location: backend/kobic_server/test/unit/{feature_name}/

Test Targets:

  • {feature}_endpoint_test.dart (endpoint unit tests)
  • {feature}_service_test.dart (service logic unit tests)

Integration Tests

# Run withServerpod integration tests
melos exec --scope=kobic_server -- \
  dart test test/integration/{feature_name}/ --reporter expanded

Test Location: backend/kobic_server/test/integration/{feature_name}/

Test Targets:

  • {feature}_integration_test.dart

Verification Items:

  • Auth-required endpoints: ServerpodUnauthenticatedException verification
  • Permission checks: ServerpodInsufficientAccessException verification
  • CRUD flow: Create → Read → Update → Delete scenarios
  • Error cases: NotFoundException, ValidationException verification

Auto-Fix Patterns#

Fixable Failure Types#

Failure TypeCauseAuto-Fix Method
Missing MockNo when() setupAdd Mock setup
State mismatchExpected State differs from actualUpdate State values
Widget not foundWrong Key/FinderFix Finder
Missing importRequired import missingAdd import
TimeoutAsync processing delayAdjust pumpAndSettle

Non-Fixable Failure Types#

Failure TypeReason
Logic errorRequires business logic judgment
Architecture issueRequires design changes
External dependencyExternal service issue

Auto-Fix Flow#

1. Parse failure message
   ↓
2. Classify failure type
   ↓
3. Determine if fixable
   ↓
4. Generate fix code
   ↓
5. Apply fix
   ↓
6. Re-run test
   ↓
7. Verify success/failure

Melos Script Usage#

Single Feature Test#

# Test specific Feature only
melos exec --scope=feature_{feature_name} -- flutter test

# Or
melos run test --scope=feature_{feature_name}

Test with Coverage#

# Test with coverage
melos run test:with-html-coverage

Run Specific Test File#

# Single file test
melos exec --scope=feature_{feature_name} -- \
  flutter test test/domain/usecase/get_posts_usecase_test.dart

Result Report#

Console Output Format#

╔════════════════════════════════════════════════════════╗
║  Test Results: feature_community                       ║
╠════════════════════════════════════════════════════════â•Ģ
║  Unit Tests (UseCase):                                 ║
║    ✅ GetPostsUseCase: 5 passed                        ║
║    ✅ GetPostUseCase: 3 passed                         ║
║    ✅ CreatePostUseCase: 4 passed                      ║
║                                                        ║
║  BLoC Tests:                                           ║
║    ✅ PostListBloc: 8 passed                           ║
║    ✅ PostDetailBloc: 6 passed                         ║
║    ❌ PostFormBloc: 4 passed, 1 failed                 ║
║                                                        ║
║  BDD Widget Tests:                                     ║
║    ✅ community_list.feature: 7 scenarios passed       ║
║    ✅ community_detail.feature: 5 scenarios passed     ║
║                                                        ║
╠════════════════════════════════════════════════════════â•Ģ
║  Summary: 42/43 passed (97.7%)                         ║
║  Duration: 45.3s                                       ║
║  Coverage: 85.2% (lines)                               ║
╚════════════════════════════════════════════════════════╝

Failure Detail Report#

╔════════════════════════════════════════════════════════╗
║  Failed Test Details                                   ║
╠════════════════════════════════════════════════════════â•Ģ
║  File: post_form_bloc_test.dart                        ║
║  Test: should emit error state when validation fails   ║
║                                                        ║
║  Error:                                                ║
║    Expected: PostFormError(message:  " Title required " )  ║
║    Actual:   PostFormError(message:  " 렜ëŠĐė„ ėž…ë Ĩ하ė„ļėš” " )  ║
║                                                        ║
║  Fixable: ✅ Yes (message mismatch)                    ║
║  Auto-fix: Applied                                     ║
╚════════════════════════════════════════════════════════╝

Error Handling#

On Build Failure#

1. Check analysis errors
2. Re-run code generation
3. If still failing → report failure

Test Timeout#

1. Individual test timeout: 30 seconds
2. Overall test timeout: 10 minutes
3. On timeout → skip that test and continue

Key Rules#

  1. Build First: Verify build success before tests
  2. Follow Order: Execute in Unit → BLoC → BDD order
  3. Auto-Fix Limit: Attempt up to 3 times only
  4. Failure Tolerance: Skip and report on non-fixable failures
  5. Coverage Target: Minimum 80% line coverage
  6. Detailed Logs: Provide detailed information for all failures