Documentation
Coding Studio

Tests Tool

Generate comprehensive test suites automatically. Includes test plans, edge cases, mocking strategies, and framework-specific setup.

Keyboard shortcut: Cmd/Ctrl + 6

What It Does

The Tests tool analyzes your code and generates comprehensive test suites with proper structure and coverage:

Test Plans

Generates a structured test plan identifying what should be tested, including happy paths, edge cases, and error scenarios.

Edge Case Coverage

Automatically identifies and tests edge cases: empty inputs, nulls, boundary values, invalid data, and concurrent access.

Mock Strategies

Provides mocking strategies for external dependencies: APIs, databases, file systems, and third-party services.

Framework Setup

Includes framework-specific configuration, setup/teardown hooks, and proper test organization patterns.

Supported Test Frameworks

FrameworkLanguagesRun Command
JestJavaScript, TypeScriptnpm test
VitestJavaScript, TypeScriptnpx vitest
MochaJavaScript, TypeScriptnpx mocha
pytestPythonpytest
unittestPythonpython -m unittest
Go TestGogo test ./...
JUnitJava, Kotlinmvn test
xUnitC#dotnet test
RSpecRubyrspec
PHPUnitPHPvendor/bin/phpunit

Context Fields

FieldDescription
Test FrameworkThe testing framework to use (auto-suggested based on language)

How to Use

1

Select Tests Tool

Click the Tests button (cyan icon) or pressCmd/Ctrl + 6.

2

Paste Code to Test

Enter the function, class, or module you want to test. Include type definitions for better test generation.

3

Select Test Framework

Choose your preferred testing framework from the dropdown. The tool auto-suggests based on your language.

4

Click "Generate Tests"

Run the generation. The tool analyzes your code structure and creates comprehensive test coverage.

5

Review and Copy

Check the test plan in the Result tab, then use the Files tab to download the generated test files.

Example

Given this function:

validate-email.tsTypeScript
export function validateEmail(email: string): {
  isValid: boolean;
  errors: string[];
} {
  const errors: string[] = [];

  if (!email || email.trim().length === 0) {
    errors.push('Email is required');
    return { isValid: false, errors };
  }

  if (email.length > 254) {
    errors.push('Email exceeds maximum length');
  }

  if (email.includes('..')) {
    errors.push('Email contains consecutive dots');
  }

  const emailRegex = /^[^@]+@[^@]+.[^@]+$/;
  if (!emailRegex.test(email)) {
    errors.push('Invalid email format');
  }

  return { isValid: errors.length === 0, errors };
}

The Tests tool generates:

validate-email.test.tsTypeScript
import { describe, it, expect } from 'vitest';
import { validateEmail } from './validate-email';

describe('validateEmail', () => {
  describe('valid emails', () => {
    it('should accept standard email format', () => {
      const result = validateEmail('user@example.com');
      expect(result.isValid).toBe(true);
      expect(result.errors).toHaveLength(0);
    });

    it('should accept email with subdomain', () => {
      const result = validateEmail('user@mail.example.com');
      expect(result.isValid).toBe(true);
    });

    it('should accept email with plus addressing', () => {
      const result = validateEmail('user+tag@example.com');
      expect(result.isValid).toBe(true);
    });
  });

  describe('empty input', () => {
    it('should reject empty string', () => {
      const result = validateEmail('');
      expect(result.isValid).toBe(false);
      expect(result.errors).toContain('Email is required');
    });

    it('should reject whitespace only', () => {
      const result = validateEmail('   ');
      expect(result.isValid).toBe(false);
      expect(result.errors).toContain('Email is required');
    });

    it('should handle null-like values', () => {
      // @ts-expect-error testing invalid input
      const result = validateEmail(null);
      expect(result.isValid).toBe(false);
    });
  });

  describe('length validation', () => {
    it('should accept email at max length (254)', () => {
      const localPart = 'a'.repeat(64);
      const domain = 'b'.repeat(185) + '.com';
      const email = `${localPart}@${domain}`.slice(0, 254);
      const result = validateEmail(email);
      // May have format errors but not length error
      expect(result.errors).not.toContain('Email exceeds maximum length');
    });

    it('should reject email exceeding max length', () => {
      const email = 'a'.repeat(255) + '@example.com';
      const result = validateEmail(email);
      expect(result.errors).toContain('Email exceeds maximum length');
    });
  });

  describe('format validation', () => {
    it('should reject consecutive dots', () => {
      const result = validateEmail('user..name@example.com');
      expect(result.isValid).toBe(false);
      expect(result.errors).toContain('Email contains consecutive dots');
    });

    it('should reject missing @ symbol', () => {
      const result = validateEmail('userexample.com');
      expect(result.isValid).toBe(false);
      expect(result.errors).toContain('Invalid email format');
    });

    it('should reject missing domain', () => {
      const result = validateEmail('user@');
      expect(result.isValid).toBe(false);
    });

    it('should reject missing local part', () => {
      const result = validateEmail('@example.com');
      expect(result.isValid).toBe(false);
    });
  });

  describe('multiple errors', () => {
    it('should collect all validation errors', () => {
      const email = 'a'.repeat(300) + '..@invalid';
      const result = validateEmail(email);
      expect(result.isValid).toBe(false);
      expect(result.errors.length).toBeGreaterThan(1);
    });
  });
});

Test Organization

Generated tests follow best practices for organization:

  • Describe blocks: Group tests by functionality or scenario
  • Meaningful names: Test names describe expected behavior
  • AAA pattern: Arrange, Act, Assert structure
  • Isolation: Each test is independent and can run alone
  • Edge cases first: Boundary conditions are prioritized

Running Generated Tests

After copying the test file, install the testing framework if needed (e.g., npm install -D vitest) and run with the appropriate command shown in the test file header.

Mocking Dependencies

For code with external dependencies (APIs, databases), the tool includes mock implementations and explains how to set up test doubles properly.