Skip to main content
Glama

generate_unit_tests

Generate comprehensive unit tests for code with framework-specific patterns and complete coverage strategies to ensure production-ready quality.

Instructions

Generate comprehensive unit tests for code with framework-specific patterns and complete coverage strategies

WORKFLOW: Ideal for creating production-ready code, tests, and documentation TIP: Generate unlimited iterations locally, then review with Claude SAVES: Claude context for strategic decisions

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
codeNoThe code to generate tests for (for single-file analysis)
contextNoOptional context for framework-specific testing patterns
coverageTargetNoTest coverage target levelcomprehensive
filePathNoPath to single file to generate tests for
filesNoArray of specific file paths (for multi-file test generation)
languageNoProgramming languagejavascript
maxDepthNoMaximum directory depth for multi-file discovery (1-5)
projectPathNoPath to project root (for multi-file test generation)
testFrameworkNoTesting framework to use (jest, mocha, pytest, phpunit, etc.)jest

Implementation Reference

  • Main handler function that executes the generate_unit_tests tool. Detects single or multi-file mode, validates params, sets up LLM model, and routes to appropriate analysis method.
    async execute(params: any, llmClient: any) { return await withSecurity(this, params, llmClient, async (secureParams) => { try { // 1. Auto-detect analysis mode based on parameters const analysisMode = this.detectAnalysisMode(secureParams); // 2. Validate parameters based on detected mode this.validateParameters(secureParams, analysisMode); // 3. Setup model const { model, contextLength } = await ModelSetup.getReadyModel(llmClient); // 4. Route to appropriate analysis method if (analysisMode === 'single-file') { return await this.executeSingleFileAnalysis(secureParams, model, contextLength); } else { return await this.executeMultiFileAnalysis(secureParams, model, contextLength); } } catch (error: any) { return ErrorHandler.createExecutionError('generate_unit_tests', error); } }); }
  • Input parameter schema definition for the generate_unit_tests tool, supporting both single-file and multi-file modes with framework and coverage options.
    parameters = { // Single-file parameters code: { type: 'string' as const, description: 'The code to generate tests for (for single-file analysis)', required: false }, filePath: { type: 'string' as const, description: 'Path to single file to generate tests for', required: false }, // Multi-file parameters projectPath: { type: 'string' as const, description: 'Path to project root (for multi-file test generation)', required: false }, files: { type: 'array' as const, description: 'Array of specific file paths (for multi-file test generation)', required: false, items: { type: 'string' as const } }, maxDepth: { type: 'number' as const, description: 'Maximum directory depth for multi-file discovery (1-5)', required: false, default: 3 }, // Universal parameters language: { type: 'string' as const, description: 'Programming language', required: false, default: 'javascript' }, testFramework: { type: 'string' as const, description: 'Testing framework to use (jest, mocha, pytest, phpunit, etc.)', required: false, default: 'jest' }, coverageTarget: { type: 'string' as const, description: 'Test coverage target level', enum: ['basic', 'comprehensive', 'edge-cases'], default: 'comprehensive', required: false }, context: { type: 'object' as const, description: 'Optional context for framework-specific testing patterns', required: false, properties: { projectType: { type: 'string' as const, enum: ['wordpress-plugin', 'wordpress-theme', 'react-app', 'react-component', 'node-api', 'browser-extension', 'cli-tool', 'n8n-node', 'n8n-workflow', 'generic'], description: 'Project type for appropriate test patterns' }, testStyle: { type: 'string' as const, enum: ['bdd', 'tdd', 'aaa', 'given-when-then'], description: 'Testing style preference' }, mockStrategy: { type: 'string' as const, enum: ['minimal', 'comprehensive', 'integration-preferred'], description: 'Mocking approach', default: 'minimal' } } } };
  • Output response schema (TypeScript interface) for generate_unit_tests tool.
    export interface GenerateUnitTestsResponse extends BaseResponse { data: { tests: string; coverage: { functions: string[]; branches: number; lines: number; }; testCount: number; testTypes: { unit: number; integration?: number; performance?: number; edgeCases?: number; }; mocks: string[]; setupRequired: string[]; }; }
  • Plugin registration method in PluginLoader. The UnitTestGenerator is dynamically loaded and registered here by its name 'generate_unit_tests'.
    registerPlugin(plugin: IPromptPlugin): void { // Validate plugin has required properties if (!plugin.name || !plugin.category || !plugin.execute) { throw new Error('Invalid plugin: missing required properties'); } // Register in main map this.plugins.set(plugin.name, plugin); // Register in category map const categoryPlugins = this.categories.get(plugin.category) || []; categoryPlugins.push(plugin); this.categories.set(plugin.category, categoryPlugins); }
  • Response type mapping for generate_unit_tests in FunctionResponseMap.
    'generate_unit_tests': GenerateUnitTestsResponse; 'generate_documentation': GenerateDocumentationResponse;

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/houtini-ai/lm'

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