flutter_test_suite
Execute comprehensive Flutter testing including unit, widget, and integration tests with coverage reporting to validate mobile application functionality and quality.
Instructions
Run complete test suite: unit tests, widget tests, integration tests with coverage report
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| cwd | Yes | Working directory (Flutter project root) | |
| coverage | No | Generate coverage report | |
| integrationTests | No | Include integration tests |
Implementation Reference
- src/tools/super-tools.ts:255-308 (handler)Main execution logic for flutter_test_suite: composes flutter_test for unit/widget tests, runs integration tests directly, generates HTML coverage report.handler: async (args: any) => { const results = { unit: null as any, widget: null as any, integration: null as any, coverage: null as any }; try { // Run unit and widget tests const testTool = flutterTools.get('flutter_test'); results.unit = await testTool.handler({ cwd: args.cwd, coverage: args.coverage }); // Run integration tests if requested if (args.integrationTests) { const { stdout } = await processExecutor.execute( 'flutter', ['test', 'integration_test'], { cwd: args.cwd } ); results.integration = { success: true, data: stdout }; } // Generate coverage report if (args.coverage) { const { stdout } = await processExecutor.execute( 'genhtml', ['coverage/lcov.info', '-o', 'coverage/html'], { cwd: args.cwd } ); results.coverage = { success: true, data: { htmlReport: 'coverage/html/index.html', lcovFile: 'coverage/lcov.info' } }; } return { success: true, data: results }; } catch (error) { return { success: false, error: error instanceof Error ? error.message : String(error), data: results }; } }
- src/tools/super-tools.ts:235-254 (schema)Input validation schema defining parameters for the flutter_test_suite tool.inputSchema: { type: 'object', properties: { cwd: { type: 'string', description: 'Working directory (Flutter project root)' }, coverage: { type: 'boolean', description: 'Generate coverage report', default: true }, integrationTests: { type: 'boolean', description: 'Include integration tests', default: false } }, required: ['cwd'] },
- src/tools/super-tools.ts:231-309 (registration)Registration of the flutter_test_suite tool in the super-tools map created by createSuperTools.// Flutter Test Suite - Complete testing workflow tools.set('flutter_test_suite', { name: 'flutter_test_suite', description: 'Run complete test suite: unit tests, widget tests, integration tests with coverage report', inputSchema: { type: 'object', properties: { cwd: { type: 'string', description: 'Working directory (Flutter project root)' }, coverage: { type: 'boolean', description: 'Generate coverage report', default: true }, integrationTests: { type: 'boolean', description: 'Include integration tests', default: false } }, required: ['cwd'] }, handler: async (args: any) => { const results = { unit: null as any, widget: null as any, integration: null as any, coverage: null as any }; try { // Run unit and widget tests const testTool = flutterTools.get('flutter_test'); results.unit = await testTool.handler({ cwd: args.cwd, coverage: args.coverage }); // Run integration tests if requested if (args.integrationTests) { const { stdout } = await processExecutor.execute( 'flutter', ['test', 'integration_test'], { cwd: args.cwd } ); results.integration = { success: true, data: stdout }; } // Generate coverage report if (args.coverage) { const { stdout } = await processExecutor.execute( 'genhtml', ['coverage/lcov.info', '-o', 'coverage/html'], { cwd: args.cwd } ); results.coverage = { success: true, data: { htmlReport: 'coverage/html/index.html', lcovFile: 'coverage/lcov.info' } }; } return { success: true, data: results }; } catch (error) { return { success: false, error: error instanceof Error ? error.message : String(error), data: results }; } } });
- src/tools/flutter.ts:720-785 (helper)Supporting flutter_test tool used by flutter_test_suite for running unit and widget tests.tools.set('flutter_test', { name: 'flutter_test', description: 'Run Flutter tests with optional coverage', inputSchema: { type: 'object', properties: { cwd: { type: 'string', minLength: 1, description: 'Working directory (Flutter project root)' }, testFile: { type: 'string', description: 'Specific test file to run (optional)' }, coverage: { type: 'boolean', description: 'Enable test coverage' } }, required: ['cwd'] }, handler: async (args: any) => { const validation = FlutterTestSchema.safeParse(args); if (!validation.success) { throw new Error(`Invalid request: ${validation.error.message}`); } const { cwd, testFile, coverage = false } = validation.data; // Validate that it's a Flutter project await validateFlutterProject(cwd); const flutter_args = ['test']; if (testFile) { // Validate test file path (must be .dart file in test directory) if (!testFile.endsWith('.dart')) { throw new Error(`Test file must be a .dart file. Invalid test file: ${testFile}`); } // Check if test file exists const testFilePath = path.isAbsolute(testFile) ? testFile : path.join(cwd, testFile); try { await fs.access(testFilePath); } catch { throw new Error(`Test file not found. File does not exist: ${testFilePath}`); } flutter_args.push(testFile); } if (coverage) { flutter_args.push('--coverage'); } const result = await processExecutor.execute('flutter', flutter_args, { cwd, timeout: 600000, // 10 minutes timeout for tests }); return { success: true, data: { testFile: testFile || 'all tests', coverage, projectPath: cwd, exitCode: result.exitCode, output: result.stdout, errors: result.stderr, duration: result.duration, passed: result.exitCode === 0, }, }; } });
- src/server.ts:61-71 (registration)Top-level registration loop that adds superTools (including flutter_test_suite) to the main MCP tools map if present in TOOL_REGISTRY.for (const toolName of Object.keys(TOOL_REGISTRY)) { if (allAvailableTools.has(toolName)) { tools.set(toolName, allAvailableTools.get(toolName)); } else if (toolName === 'health_check') { // health_check is handled separately below continue; } else { // Tool is in registry but not implemented - log warning console.warn(`Warning: Tool '${toolName}' is in TOOL_REGISTRY but not implemented`); } }