test_code
Automatically generates test cases for provided code, supporting custom test frameworks to ensure robust functionality and quality assurance.
Instructions
Generates tests for the given code.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| code | Yes | Code to test | |
| test_framework | No | Test framework to use |
Implementation Reference
- claude-code-server/src/index.ts:571-582 (handler)Handler implementation for the 'test_code' tool. It destructures the input arguments, encodes the code to base64, constructs a prompt for generating tests using Claude CLI, executes it, and returns the generated test code as text content.case 'test_code': { const { code, test_framework } = args; logger.debug(`Processing test_code request, code length: ${code.length}`); const encodedCode = encodeText(truncateIfNeeded(code)); logger.debug(`Code encoded to base64, length: ${encodedCode.length}`); const framework = test_framework || 'default'; const prompt = `You are super professional engineer. Please generate tests for the following Base64 encoded code.\n\nCode:\n${encodedCode}\n\nTest framework (if specified):\n${framework || 'No specific framework provided. Please use a suitable default framework.'}`; logger.debug('Calling Claude CLI with prompt'); const output = await runClaudeCommand(['--print'], prompt); logger.debug(`Received response from Claude, length: ${output.length}`); return { content: [{ type: 'text', text: output }] }; }
- claude-code-server/src/index.ts:371-382 (registration)Registration of the 'test_code' tool in the ListTools response, including its name, description, and input schema definition.{ name: 'test_code', description: 'Generates tests for the given code.', inputSchema: { type: 'object', properties: { code: { type: 'string', description: 'Code to test' }, test_framework: { type: 'string', description: 'Test framework to use', default: '' } }, required: ['code'] } },
- Input schema definition for the 'test_code' tool, specifying the expected parameters: code (required string) and optional test_framework.inputSchema: { type: 'object', properties: { code: { type: 'string', description: 'Code to test' }, test_framework: { type: 'string', description: 'Test framework to use', default: '' } }, required: ['code'] } },