Skip to main content
Glama

run_unit_tests

Execute unit tests for Android or iOS applications to validate code functionality and identify issues with detailed pass/fail results.

Instructions

Run unit tests for Android or iOS. Returns structured test results with pass/fail status and failure details.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
platformYesTarget platform
projectPathYesPath to the project root directory
sourceSetNoSource set to test (test, commonTest, androidTest, iosTest)
testClassNoSpecific test class to run (optional)
testMethodNoSpecific test method to run (requires testClass)
moduleNoGradle module for KMM projects (e.g., :shared)
timeoutMsNoTimeout in milliseconds (default: 300000)

Implementation Reference

  • Main handler function for the 'run_unit_tests' MCP tool. It destructures arguments, validates the platform, and delegates to platform-specific test execution functions (runAndroidTests or runIOSTests).
    export async function runUnitTests(args: RunUnitTestsArgs): Promise<RunUnitTestsResult> {
      const {
        platform,
        projectPath,
        sourceSet = 'test',
        testClass,
        testMethod,
        module = '',
        timeoutMs = 300000,
      } = args;
    
      // Validate platform
      if (!isPlatform(platform)) {
        throw Errors.invalidArguments(`Invalid platform: ${platform}. Must be 'android' or 'ios'`);
      }
    
      if (platform === 'android') {
        return runAndroidTests({
          projectPath,
          sourceSet,
          testClass,
          testMethod,
          module,
          timeoutMs,
        });
      } else {
        return runIOSTests({
          projectPath,
          sourceSet,
          testClass,
          testMethod,
          timeoutMs,
        });
      }
    }
  • TypeScript interfaces defining the input arguments (RunUnitTestsArgs) and output result structure (RunUnitTestsResult) for the run_unit_tests tool.
    export interface RunUnitTestsArgs {
      /** Target platform */
      platform: string;
      /** Project root directory */
      projectPath: string;
      /** Source set (commonTest, androidTest, iosTest) */
      sourceSet?: string;
      /** Specific test class to run */
      testClass?: string;
      /** Specific test method to run */
      testMethod?: string;
      /** Gradle module for KMM projects */
      module?: string;
      /** Timeout in milliseconds */
      timeoutMs?: number;
    }
    
    /**
     * Result structure for run_unit_tests
     */
    export interface RunUnitTestsResult {
      /** Test execution result */
      result: TestResult;
      /** Human-readable summary */
      summary: string;
      /** Extracted failures with suggestions */
      failures: ReturnType<typeof extractTestFailures>;
    }
  • The registration function for the 'run_unit_tests' tool. It registers the tool with the global ToolRegistry, providing the tool name, description, detailed input JSON schema, and the handler function.
    export function registerRunUnitTestsTool(): void {
      getToolRegistry().register(
        'run_unit_tests',
        {
          description:
            'Run unit tests for Android or iOS. Returns structured test results with pass/fail status and failure details.',
          inputSchema: createInputSchema(
            {
              platform: {
                type: 'string',
                enum: ['android', 'ios'],
                description: 'Target platform',
              },
              projectPath: {
                type: 'string',
                description: 'Path to the project root directory',
              },
              sourceSet: {
                type: 'string',
                description: 'Source set to test (test, commonTest, androidTest, iosTest)',
              },
              testClass: {
                type: 'string',
                description: 'Specific test class to run (optional)',
              },
              testMethod: {
                type: 'string',
                description: 'Specific test method to run (requires testClass)',
              },
              module: {
                type: 'string',
                description: 'Gradle module for KMM projects (e.g., :shared)',
              },
              timeoutMs: {
                type: 'number',
                description: 'Timeout in milliseconds (default: 300000)',
              },
            },
            ['platform', 'projectPath']
          ),
        },
        (args) => runUnitTests(args as unknown as RunUnitTestsArgs)
      );
    }
  • Helper function implementing Android unit test execution via Gradle. Checks ADB availability for instrumentation tests, runs tests, processes results into summary and failures.
    async function runAndroidTests(options: {
      projectPath: string;
      sourceSet: string;
      testClass?: string;
      testMethod?: string;
      module: string;
      timeoutMs: number;
    }): Promise<RunUnitTestsResult> {
      // Check if ADB is available
      const adbAvailable = await isAdbAvailable();
      if (!adbAvailable && options.sourceSet === 'androidTest') {
        throw Errors.platformUnavailable('android');
      }
    
      const testOptions: TestRunOptions = {
        projectPath: options.projectPath,
        sourceSet: options.sourceSet,
        testClass: options.testClass,
        testMethod: options.testMethod,
        module: options.module,
        timeoutMs: options.timeoutMs,
      };
    
      const result = await runGradleTests(testOptions);
      const summary = createTestSummary(result);
      const failures = extractTestFailures(result);
    
      return { result, summary, failures };
    }
  • Invocation of the tool registration during central registerAllTools() call in server startup, ensuring the tool is registered in the global registry.
    const { registerRunUnitTestsTool } = await import('./testing/run-unit-tests.js');
    const { registerRunMaestroFlowTool } = await import('./testing/run-maestro-flow.js');
    const { registerRunLinterTool } = await import('./testing/run-linter.js');
    
    registerRunUnitTestsTool();
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations provided, the description carries the full burden of behavioral disclosure. It states the tool returns structured test results, which is helpful, but lacks critical details like whether it's read-only (likely not, as it executes tests), potential side effects (e.g., test execution might modify logs or require app installation), error handling, or performance implications (e.g., timeout default).

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is a single, efficient sentence that front-loads the core purpose and key output. Every word earns its place, with no redundancy or unnecessary elaboration.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness3/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the complexity (7 parameters, no annotations, no output schema), the description is minimal but covers the basic purpose and output. It lacks details on behavioral traits, usage context, and error scenarios, making it adequate but with clear gaps for a tool that executes tests.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is 100%, so the schema fully documents all 7 parameters. The description adds no parameter-specific information beyond implying platform and result context, which is already covered by the schema. Baseline 3 is appropriate as the schema does the heavy lifting.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the action ('Run unit tests') and target ('for Android or iOS'), which is specific and distinguishes it from most siblings like 'build_app' or 'run_linter'. However, it doesn't explicitly differentiate from 'run_maestro_flow' (which might involve testing but is more about automation flows).

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description provides no guidance on when to use this tool versus alternatives like 'run_linter' (for code quality) or 'analyze_crash' (for debugging). It mentions the platforms but doesn't specify prerequisites, such as needing a configured project or test environment.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

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/abd3lraouf/specter-mcp'

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