CreateCdsUnitTest
Create a CDS unit test class with validation for a specified CDS view, including initial test double setup for unit testing.
Instructions
Create a CDS unit test class with CDS validation. Creates the test class in initial state.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| class_name | Yes | Global test class name (e.g., ZCL_CDS_TEST). | |
| package_name | Yes | Package name (e.g., ZOK_TEST_PKG_01, $TMP). | |
| cds_view_name | Yes | CDS view name to validate for unit test doubles. | |
| description | No | Optional description for the global test class. | |
| transport_request | No | Transport request number (required for transportable packages). |
Implementation Reference
- Main handler function for CreateCdsUnitTest MCP tool. Uses AdtClient.getCdsUnitTest().create() to create a CDS unit test class with ADT lifecycle (validate + create). Extracts args (class_name, package_name, cds_view_name, etc.), validates required params, calls the ADT client, and returns a JSON stringified response with test class state.
export async function handleCreateCdsUnitTest( context: HandlerContext, args: CreateCdsUnitTestArgs, ) { const { connection, logger } = context; try { const { class_name, package_name, cds_view_name, class_template, test_class_source, description, transport_request, } = args as CreateCdsUnitTestArgs; if (!class_name || !package_name || !cds_view_name) { return return_error( new Error( 'Missing required parameters: class_name, package_name, cds_view_name', ), ); } const className = class_name.toUpperCase(); const cdsViewName = cds_view_name.toUpperCase(); const client = createAdtClient(connection, logger); const cdsUnitTest = client.getCdsUnitTest(); logger?.info( `Creating CDS unit test class ${className} for CDS view ${cdsViewName}`, ); try { const createResult = await cdsUnitTest.create({ className, packageName: package_name, cdsViewName, classTemplate: class_template || '', testClassSource: test_class_source || '', description, transportRequest: transport_request, }); if (!createResult?.testClassState) { throw new Error( `Create did not return a response for CDS unit test class ${className}`, ); } logger?.info(`✅ CreateCdsUnitTest completed successfully: ${className}`); // Extract safe fields — testClassState contains AxiosResponse objects // with circular references that cannot be JSON.stringified const safeState = { testClassCode: createResult.testClassState?.testClassCode, lockHandle: createResult.testClassState?.lockHandle, errors: createResult.testClassState?.errors, }; return return_response({ data: JSON.stringify( { success: true, class_name: className, cds_view_name: cdsViewName, test_class_state: safeState, message: `CDS unit test class ${className} created successfully.`, }, null, 2, ), } as AxiosResponse); } catch (error: any) { logger?.error( `Error creating CDS unit test class ${className}: ${error?.message || error}`, ); return return_error(new Error(error?.message || String(error))); } } catch (error: any) { return return_error(error); } } - Tool definition/schema for CreateCdsUnitTest. Defines name 'CreateCdsUnitTest', availability ('onprem', 'cloud', 'legacy'), description, and inputSchema with properties: class_name (string), package_name (string), cds_view_name (string), description (optional string), transport_request (optional string). Required fields: class_name, package_name, cds_view_name.
export const TOOL_DEFINITION = { name: 'CreateCdsUnitTest', available_in: ['onprem', 'cloud', 'legacy'] as const, description: 'Create a CDS unit test class with CDS validation. Creates the test class in initial state.', inputSchema: { type: 'object', properties: { class_name: { type: 'string', description: 'Global test class name (e.g., ZCL_CDS_TEST).', }, package_name: { type: 'string', description: 'Package name (e.g., ZOK_TEST_PKG_01, $TMP).', }, cds_view_name: { type: 'string', description: 'CDS view name to validate for unit test doubles.', }, description: { type: 'string', description: 'Optional description for the global test class.', }, transport_request: { type: 'string', description: 'Transport request number (required for transportable packages).', }, }, required: ['class_name', 'package_name', 'cds_view_name'], }, } as const; - src/lib/handlers/groups/HighLevelHandlersGroup.ts:805-808 (registration)Registration of CreateCdsUnitTest in HighLevelHandlersGroup. Maps the CreateCdsUnitTest_Tool (imported from handleCreateCdsUnitTest.ts) to the handler wrapped with withContext(handleCreateCdsUnitTest).
{ toolDefinition: CreateCdsUnitTest_Tool, handler: withContext(handleCreateCdsUnitTest), }, - src/lib/handlers/groups/HighLevelHandlersGroup.ts:400-403 (registration)Import of CreateCdsUnitTest tool definition (renamed to CreateCdsUnitTest_Tool) and handler from '../../../handlers/unit_test/high/handleCreateCdsUnitTest'.
import { TOOL_DEFINITION as CreateCdsUnitTest_Tool, handleCreateCdsUnitTest, } from '../../../handlers/unit_test/high/handleCreateCdsUnitTest'; - src/handlers/compact/high/compactRouter.ts:164-165 (registration)Registration of handleCreateCdsUnitTest in compact router for CDS_UNIT_TEST object type under the 'create' CRUD operation.
CDS_UNIT_TEST: { create: handleCreateCdsUnitTest as unknown as CompactHandler,