Skip to content
Documentation
Command

/test

Generate tests for code - unit tests, integration tests, or edge cases

From plugin
claude-code-mastery
5584 skills4 commands5 hooks
$ npx -y skills add TheDecipherist/claude-code-mastery --agent claude-code

Command definition

test.md
description: Generate tests for code - unit tests, integration tests, or edge cases

Generate Tests

Generate comprehensive tests for the specified code.

Input

The user will provide one of:

  • A file path: `/test src/utils/validators.ts`
  • A function name: `/test validateEmail`
  • Just `/test` — generate tests for recently changed files

Optional flags via $ARGUMENTS:

  • `--unit` — unit tests only (default)
  • `--integration` — integration tests
  • `--edge` — focus on edge cases
  • `--coverage` — aim for high coverage

Process

1. Detect Test Framework

Check the project for:

  • `vitest.config.*` → Vitest
  • `jest.config.*` → Jest
  • `*.test.ts` patterns → Match existing style
  • `pytest.ini` or `conftest.py` → Pytest
  • `go.mod` → Go testing

If unclear, ask the user.

2. Analyze the Code

Identify:

  • Public functions/methods to test
  • Input types and valid ranges
  • Expected outputs
  • Error conditions
  • Side effects (mocking needed?)
  • Dependencies (what to mock?)

3. Generate Test Cases

For each function, create tests for:

**Happy Path**

  • Normal input → expected output
  • Common use cases

**Edge Cases**

  • Empty input ([], "", null, undefined)
  • Boundary values (0, -1, MAX_INT)
  • Single element collections
  • Very large inputs

**Error Cases**

  • Invalid input types
  • Out of range values
  • Missing required fields
  • Network/IO failures (if applicable)

4. Test Structure

Follow AAA pattern:

describe('functionName', () => {
  it('should return X when given Y', () => {
    // Arrange
    const input = { ... };

    // Act
    const result = functionName(input);

    // Assert
    expect(result).toEqual(expected);
  });
});

5. Naming Convention

Test names should be readable as sentences:

  • `should return empty array when input is empty`
  • `should throw ValidationError when email is invalid`
  • `should call API once per unique user`

NOT:

  • `test1`
  • `works`
  • `validateEmail test`

Output

1. Create test file at conventional location:

  • `src/foo.ts` → `src/foo.test.ts` or `__tests__/foo.test.ts`
  • `foo.py` → `test_foo.py` or `tests/test_foo.py`

2. Show summary:

  • Number of test cases generated
  • Coverage estimate
  • Any functions skipped and why

3. Run the tests to verify they pass:

   npm test -- --run <test-file>

Guidelines

  • Don't test implementation details, test behavior
  • One assertion per test when possible
  • Mock external dependencies, not internal code
  • Tests should be deterministic (no random, no Date.now())
  • Fast tests — avoid real network/database calls
Read more
@thedecipherist
Ships withclaude-code-mastery

The complete guide to maximizing Claude Code: Global CLAUDE.md, MCP Servers, Commands, Hooks, Skills, and Why Single-Purpose Chats Matter. This version is obsolete by now.

Stars on GitHub

Momentum

stars in total
558
Star history of TheDecipherist/claude-code-mastery on GitHub, a chart by star-history.com

Other commands on claude-code-mastery.

More commands from other plugins.

maintainer
Auto-invoked

maintainer

Command

Meta-skill that loads all llmwiki governance docs and exposes the three maintainer slash commands.

llmwiki4mo400
@pratiyush@pratiyushInstall Command