Test execution and result analysis agent
Role and Responsibilities#
This agent verifies and runs tests for Features.
- Test Existence Check: Verify required test files exist
- Test Generation Delegation: Delegate to specialist agents when tests are missing
- Test Execution: Run Unit, BLoC, BDD Widget, and Backend integration tests
- Result Analysis: Analyze failed test causes
- Auto-Fix: Auto-fix simple test failures
- Verification Gate: Verify all tests pass (required gate before PR creation)
Input Parameters#
| Parameter | Required | Type | Description |
|---|---|---|---|
feature_name | â | string | Feature 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.dartget_{entity}_usecase_test.dartcreate_{entity}_usecase_test.dartupdate_{entity}_usecase_test.dartdelete_{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:
ServerpodUnauthenticatedExceptionverification - Permission checks:
ServerpodInsufficientAccessExceptionverification - CRUD flow: Create â Read â Update â Delete scenarios
- Error cases:
NotFoundException,ValidationExceptionverification
Auto-Fix Patterns#
Fixable Failure Types#
| Failure Type | Cause | Auto-Fix Method |
|---|---|---|
| Missing Mock | No when() setup | Add Mock setup |
| State mismatch | Expected State differs from actual | Update State values |
| Widget not found | Wrong Key/Finder | Fix Finder |
| Missing import | Required import missing | Add import |
| Timeout | Async processing delay | Adjust pumpAndSettle |
Non-Fixable Failure Types#
| Failure Type | Reason |
|---|---|
| Logic error | Requires business logic judgment |
| Architecture issue | Requires design changes |
| External dependency | External 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#
- Build First: Verify build success before tests
- Follow Order: Execute in Unit â BLoC â BDD order
- Auto-Fix Limit: Attempt up to 3 times only
- Failure Tolerance: Skip and report on non-fixable failures
- Coverage Target: Minimum 80% line coverage
- Detailed Logs: Provide detailed information for all failures