Skip to main content
Glama

flutter_test

Execute Flutter tests in a project directory to verify code functionality, with options to run specific test files and generate coverage reports.

Instructions

Run Flutter tests with optional coverage

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
cwdYesWorking directory (Flutter project root)
testFileNoSpecific test file to run (optional)
coverageNoEnable test coverage

Implementation Reference

  • The main handler function for the 'flutter_test' tool. It validates input using FlutterTestSchema, verifies the Flutter project directory, optionally specifies a test file and enables coverage, executes the 'flutter test' command via processExecutor, and returns structured results including output, errors, duration, and pass status.
    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, }, }; } });
  • Zod validation schema (FlutterTestSchema) for the flutter_test tool inputs: cwd (required), testFile (optional), coverage (optional boolean, defaults to false). Used in the handler for input validation.
    const FlutterTestSchema = z.object({ cwd: z.string().min(1), testFile: z.string().optional(), coverage: z.boolean().default(false), });
  • Registration of the 'flutter_test' tool within the createFlutterTools factory function. Includes name, description, JSON Schema for inputs (compatible with MCP), and reference to the handler function.
    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, }, }; } });
  • Exported Zod schema for FlutterTest in types module, used potentially for type inference or shared validation.
    export const FlutterTestSchema = z.object({ cwd: z.string(), testFile: z.string().optional(), coverage: z.boolean().optional(), });
  • Metadata registration in TOOL_REGISTRY for 'flutter_test', defining category, platform, requirements (Flutter), performance expectations, and safety flags.
    'flutter_test': { name: 'flutter_test', category: ToolCategory.ESSENTIAL, platform: 'flutter', requiredTools: [RequiredTool.FLUTTER], description: 'Run Flutter tests', safeForTesting: false, performance: { expectedDuration: 30000, timeout: 120000 } },

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/cristianoaredes/mcp-mobile-server'

If you have feedback or need assistance with the MCP directory API, please join our Discord server