unit-test-generator

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

View on GitHub
Author Jeremy Longshore
Namespace @jeremylongshore/claude-code-plugins-plus
Category testing
Version 1.0.0
Stars 1,193
Downloads 3
self.md verified
Table of content

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

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('a@b.c')).toBe(true); // Minimal valid email
    expect(validateEmail('user@domain.co.uk')).toBe(true); // Multiple dots
  });
});

Best Practices

The plugin follows testing best practices:

Requirements

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:

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:

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

…(truncated)

Source

View on GitHub

Tags: testing testingunit-teststest-generationjestpytestmochajunit