run_tests
Execute Unity's Test Runner tests with specified filters and modes (EditMode, PlayMode, or All), enabling efficient testing within the Unity Editor MCP Server environment.
Instructions
Runs Unity's Test Runner tests
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| testFilter | No | Optional test filter (e.g. specific test name or namespace) | |
| testMode | No | The test mode to run (EditMode, PlayMode, or All) |
Implementation Reference
- Server~/src/tools/runTestsTool.ts:56-108 (handler)Core execution logic for the 'run_tests' tool: parses parameters, sends request to McpUnity to run Unity Test Runner tests, handles response, extracts statistics and results, returns formatted text content with summary and JSON details.async function toolHandler(mcpUnity: McpUnity, params: any = {}): Promise<CallToolResult> { const { testMode = 'EditMode', testFilter = '', returnOnlyFailures = true, returnWithLogs = false } = params; // Create and wait for the test run const response = await mcpUnity.sendRequest({ method: toolName, params: { testMode, testFilter, returnOnlyFailures, returnWithLogs } }); // Process the test results if (!response.success) { throw new McpUnityError( ErrorType.TOOL_EXECUTION, response.message || `Failed to run tests: Mode=${testMode}, Filter=${testFilter || 'none'}` ); } // Extract test results const testResults = response.results || []; const testCount = response.testCount || 0; const passCount = response.passCount || 0; const failCount = response.failCount || 0; const skipCount = response.skipCount || 0; return { content: [ { type: 'text', text: response.message }, { type: 'text', text: JSON.stringify({ testCount, passCount, failCount, skipCount, results: testResults }, null, 2) } ] }; }
- Zod schema defining the input parameters for the 'run_tests' tool.const paramsSchema = z.object({ testMode: z.string().optional().default('EditMode').describe('The test mode to run (EditMode or PlayMode) - defaults to EditMode (optional)'), testFilter: z.string().optional().default('').describe('The specific test filter to run (e.g. specific test name or class name, must include namespace) (optional)'), returnOnlyFailures: z.boolean().optional().default(true).describe('Whether to show only failed tests in the results (optional)'), returnWithLogs: z.boolean().optional().default(false).describe('Whether to return the test logs in the results (optional)') });
- Server~/src/tools/runTestsTool.ts:26-46 (registration)Registration function for the 'run_tests' tool, which calls server.tool with name, description, schema, and a logging wrapper around the toolHandler.export function registerRunTestsTool(server: McpServer, mcpUnity: McpUnity, logger: Logger) { logger.info(`Registering tool: ${toolName}`); // Register this tool with the MCP server server.tool( toolName, toolDescription, paramsSchema.shape, async (params: any = {}) => { try { logger.info(`Executing tool: ${toolName}`, params); const result = await toolHandler(mcpUnity, params); logger.info(`Tool execution successful: ${toolName}`); return result; } catch (error) { logger.error(`Tool execution failed: ${toolName}`, error); throw error; } } ); }
- Server~/src/index.ts:57-57 (registration)Application-level call to register the 'run_tests' tool during server initialization.registerRunTestsTool(server, mcpUnity, toolLogger);