Skip to content

■ SKILLS // SKILL SPECS

unit-test-generator

Automatically generate comprehensive unit tests from source code with multiple testing framework support

■ [!] ON THIS PAGE ▼
■ INSTALL // npx @self.md/cli install unit-test-generator
AuthorJeremy Longshore
Namespace@jeremylongshore/claude-code-plugins-plus
Category#security
Version1.0.0
Stars★ 1,193
Downloads↓ 3
Verification[ ✓ ] self.md verified

Automatically generate comprehensive unit tests from source code with multiple testing framework support

Installation

npx claude-plugins install @jeremylongshore/claude-code-plugins-plus/unit-test-generator

Contents

Folders: commands, skills

Files: LICENSE, README.md

Documentation

Automatically generate comprehensive unit tests from source code with intelligent framework detection and best practices.

Features

  • Multi-framework support - Jest, pytest, JUnit, Go testing, RSpec, and more
  • Intelligent test generation - Analyzes code to create relevant test cases
  • Complete coverage - Happy paths, edge cases, error handling
  • Mock generation - Automatic mocking of external dependencies
  • Best practices - Arrange-Act-Assert, descriptive names, proper structure

Installation

/plugin install unit-test-generator@claude-code-plugins-plus

Usage

Generate tests for a file

/generate-tests src/utils/validator.js

Specify framework explicitly

/generate-tests --framework pytest src/api/users.py

Use shortcut

/gut models/UserModel.ts

What Gets Generated

The plugin creates test files with:

  1. Proper imports and setup - Framework-specific boilerplate
  2. Test suite organization - Logical grouping of related tests
  3. Comprehensive test cases:
    • Valid inputs (typical scenarios)
    • Invalid inputs (null, undefined, wrong types)
    • Boundary conditions (limits, empty collections)
    • Error scenarios (exceptions, failures)
    • State changes (when applicable)
  4. Mocks and stubs - For external dependencies
  5. Clear assertions - Validating expected outcomes
  6. Helpful comments - Explaining complex scenarios

Supported Languages & Frameworks

LanguageFrameworks
JavaScript/TypeScriptJest, Mocha, Vitest, Jasmine
Pythonpytest, unittest, nose2
JavaJUnit 5, TestNG
Gotesting package
RubyRSpec, Minitest
C#xUnit, NUnit, MSTest
PHPPHPUnit
Rustcargo test

Example Output

For a JavaScript validation function:

// Input: src/utils/validator.js
function validateEmail(email) {
  if (!email) return false;
  return /^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(email);
}

// Generated: src/utils/validator.test.js
describe('validateEmail', () => {
  it('should return true for valid email addresses', () => {
    expect(validateEmail('[email protected]')).toBe(true);
    expect(validateEmail('[email protected]')).toBe(true);
  });

  it('should return false for invalid email addresses', () => {
    expect(validateEmail('notanemail')).toBe(false);
    expect(validateEmail('@example.com')).toBe(false);
    expect(validateEmail('user@')).toBe(false);
  });

  it('should return false for null or undefined inputs', () => {
    expect(validateEmail(null)).toBe(false);
    expect(validateEmail(undefined)).toBe(false);
    expect(validateEmail('')).toBe(false);
  });

  it('should handle edge cases', () => {
    expect(validateEmail('[email protected]')).toBe(true); // Minimal valid email
    expect(validateEmail('[email protected]')).toBe(true); // Multiple dots
  });
});

Best Practices

The plugin follows testing best practices:

  • Descriptive names - Clear what is tested and expected result
  • Arrange-Act-Assert - Clear test structure
  • Test isolation - No shared state between tests
  • Single responsibility - One concept per test
  • Mock external dependencies - Database calls, API requests, etc.
  • Test both paths - Success and failure scenarios
  • Edge cases - Boundaries, nulls, empty values

Requirements

  • Claude Code CLI
  • Testing framework installed in project (e.g., npm install --save-dev jest)

Tips

  1. Review generated tests and adjust for your specific needs
  2. Add integration tests for complex workflows
  3. Update tests when code changes
  4. Aim for high coverage but prioritize meaningful tests
  5. Use generated tests as a starting point, not final solution

License

MIT

Included Skills

This plugin includes 1 skill definition:

generating-unit-tests

|

View skill definition

Unit Test Generator

This skill provides automated assistance for unit test generator tasks.

Prerequisites

Before using this skill, ensure you have:

  • Source code files requiring test coverage
  • Testing framework installed (Jest, Mocha, pytest, JUnit, etc.)
  • Understanding of code dependencies and external services to mock
  • Test directory structure established (e.g., tests/, __tests__/, spec/)
  • Package configuration updated with test scripts

Instructions

Step 1: Analyze Source Code

Examine code structure and identify test requirements:

  1. Use Read tool to load source files from {baseDir}/src/
  2. Identify all functions, classes, and methods requiring tests
  3. Document function signatures, parameters, return types, and side effects
  4. Note external dependencies requiring mocking or stubbing

Step 2: Determine Testing Framework

Select appropriate testing framework based on language:

  • JavaScript/TypeScript: Jest, Mocha, Jasmine, Vitest
  • Python: pytest, unittest, nose2
  • Java: JUnit 5, TestNG
  • Go: testing package with testify assertions
  • Ruby: RSpec, Minitest

Step 3: Generate Test Cases

Create comprehensive test suite covering:

  1. Happy path tests with valid inputs and expected outputs
  2. Edge case tests with boundary values (empty arrays, null, zero, max values)
  3. Error condition tests with invalid inputs
  4. Mock external dependencies (databases, APIs, file systems)
  5. Setup and teardown fixtures for test isolation

Step 4: Write Test Fil

Source

View on GitHub