RunUnitTest
Execute ABAP Unit tests for specified container and test classes. Returns a run ID to track test status and results.
Instructions
Start an ABAP Unit test run for provided class test definitions. Returns run_id for status/result queries.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| tests | Yes | List of container/test class pairs to execute. | |
| title | No | Optional title for the ABAP Unit run. | |
| context | No | Optional context string shown in SAP tools. | |
| scope | No | ||
| risk_level | No | ||
| duration | No |
Implementation Reference
- Main handler function for RunUnitTest tool. Uses AdtClient.getUnitTest().create() to start ABAP Unit test runs and returns a run_id for status/result queries.
export async function handleRunUnitTest( context: HandlerContext, args: RunUnitTestArgs, ) { const { connection, logger } = context; try { const { tests, title, context: contextStr, scope, risk_level, duration, } = args as RunUnitTestArgs; // Validation if (!Array.isArray(tests) || tests.length === 0) { return return_error( new Error('tests array with at least one entry is required'), ); } // Format tests for AdtClient const formattedTests = tests.map((test) => ({ containerClass: test.container_class.toUpperCase(), testClass: test.test_class.toUpperCase(), })); const client = createAdtClient(connection, logger); const unitTest = client.getUnitTest(); logger?.info( `Starting ABAP Unit run for ${formattedTests.length} test definition(s)`, ); try { // Create test run using AdtClient const createResult = await unitTest.create({ tests: formattedTests, options: { title, context: contextStr, scope: scope ? { ownTests: scope.own_tests, foreignTests: scope.foreign_tests, addForeignTestsAsPreview: scope.add_foreign_tests_as_preview, } : undefined, riskLevel: risk_level, duration, }, }); if (!createResult.runId) { throw new Error('Failed to start unit test run: run_id not returned'); } logger?.info(`✅ RunUnitTest started. Run ID: ${createResult.runId}`); return return_response({ data: JSON.stringify( { success: true, run_id: createResult.runId, message: `ABAP Unit run started. Use GetUnitTest with run_id ${createResult.runId} to get status and results.`, }, null, 2, ), } as AxiosResponse); } catch (error: any) { logger?.error(`Error starting ABAP Unit run: ${error?.message || error}`); return return_error(new Error(error?.message || String(error))); } } catch (error: any) { return return_error(error); } } - TOOL_DEFINITION export containing the RunUnitTest name, inputSchema with tests array (container_class, test_class), title, context, scope, risk_level, and duration properties.
export const TOOL_DEFINITION = { name: 'RunUnitTest', available_in: ['onprem', 'cloud', 'legacy'] as const, description: 'Start an ABAP Unit test run for provided class test definitions. Returns run_id for status/result queries.', inputSchema: { type: 'object', properties: { tests: { type: 'array', description: 'List of container/test class pairs to execute.', items: { type: 'object', properties: { container_class: { type: 'string', description: 'Class that owns the test include (e.g., ZCL_MAIN_CLASS).', }, test_class: { type: 'string', description: 'Test class name inside the include (e.g., LTCL_MAIN_CLASS).', }, }, required: ['container_class', 'test_class'], }, }, title: { type: 'string', description: 'Optional title for the ABAP Unit run.', }, context: { type: 'string', description: 'Optional context string shown in SAP tools.', }, scope: { type: 'object', properties: { own_tests: { type: 'boolean' }, foreign_tests: { type: 'boolean' }, add_foreign_tests_as_preview: { type: 'boolean' }, }, }, risk_level: { type: 'object', properties: { harmless: { type: 'boolean' }, dangerous: { type: 'boolean' }, critical: { type: 'boolean' }, }, }, duration: { type: 'object', properties: { short: { type: 'boolean' }, medium: { type: 'boolean' }, long: { type: 'boolean' }, }, }, }, required: ['tests'], }, } as const; - src/lib/handlers/groups/HighLevelHandlersGroup.ts:781-784 (registration)Registration of RunUnitTest tool in HighLevelHandlersGroup with toolDefinition and handler.
{ toolDefinition: RunUnitTest_Tool, handler: withContext(handleRunUnitTest), }, - Compact handler that delegates to handleRunUnitTest.
export async function handleHandlerUnitTestRun( context: HandlerContext, args: HandlerUnitTestRunArgs, ) { return handleRunUnitTest(context, args); } - Compact schema for unit test run (compactUnitTestRunSchema) used by HandlerUnitTestRun tool.
export const compactUnitTestRunSchema = { type: 'object', properties: { tests: { type: 'array', description: 'List of test classes to run.', items: { type: 'object', properties: { container_class: { type: 'string', description: 'Productive class containing tests.', }, test_class: { type: 'string', description: 'Local/unit test class.' }, }, required: ['container_class', 'test_class'], }, }, title: { type: 'string', description: 'Run title shown in ABAP Unit logs.', }, context: { type: 'string', description: 'Run context label.' }, scope: { type: 'object', description: 'ABAP Unit scope flags.', properties: { own_tests: { type: 'boolean', description: 'Include own tests.' }, foreign_tests: { type: 'boolean', description: 'Include foreign tests.', }, add_foreign_tests_as_preview: { type: 'boolean', description: 'Preview foreign tests without full inclusion.', }, }, }, risk_level: { type: 'object', description: 'Allowed risk levels.', properties: { harmless: { type: 'boolean', description: 'Allow harmless tests.' }, dangerous: { type: 'boolean', description: 'Allow dangerous tests.' }, critical: { type: 'boolean', description: 'Allow critical tests.' }, }, }, duration: { type: 'object', description: 'Allowed duration classes.', properties: { short: { type: 'boolean', description: 'Allow short tests.' }, medium: { type: 'boolean', description: 'Allow medium tests.' }, long: { type: 'boolean', description: 'Allow long tests.' }, }, }, }, required: ['tests'], } as const;