From unit-test-generator
Generates unit tests from source code for JS/TS (Jest/Vitest/Mocha), Python (pytest), Java (JUnit 5), Go, covering happy paths, edges, boundaries, errors with mocks.
npx claudepluginhub jeremylongshore/claude-code-plugins-plus-skills --plugin unit-test-generatorThis skill is limited to using the following tools:
Automatically generate comprehensive unit tests from source code analysis covering happy paths, edge cases, boundary conditions, and error handling. Supports Jest, Vitest, Mocha (JavaScript/TypeScript), pytest (Python), JUnit 5 (Java), and Go testing with testify.
Guides strict Test-Driven Development (TDD): write failing tests first for features, bugfixes, refactors before any production code. Enforces red-green-refactor cycle.
Guides systematic root cause investigation for bugs, test failures, unexpected behavior, performance issues, and build failures before proposing fixes.
Guides A/B test setup with mandatory gates for hypothesis validation, metrics definition, sample size calculation, and execution readiness checks.
Automatically generate comprehensive unit tests from source code analysis covering happy paths, edge cases, boundary conditions, and error handling. Supports Jest, Vitest, Mocha (JavaScript/TypeScript), pytest (Python), JUnit 5 (Java), and Go testing with testify.
jest, vitest, pytest, junit-jupiter, or Go testing)__tests__/, tests/, spec/, or *_test.go)jest.mock, unittest.mock, Mockito, or gomock)npm test, pytest, go test)src/utils/parser.ts without __tests__/parser.test.ts).null, undefined, maximum values.*.test.ts, *.spec.js, test_*.py).describe/context blocks by function name.beforeEach/afterEach for setup and teardown.| Error | Cause | Solution |
|---|---|---|
Cannot find module on import | Test file path does not match project module resolution | Check tsconfig.json paths and moduleNameMapper in Jest config |
| Mock not intercepting calls | Mock defined after module import caches the real implementation | Move jest.mock() calls to the top of the file before any imports |
| Async test timeout | Promise never resolves due to missing await or unhandled rejection | Add await before async calls; increase timeout with jest.setTimeout() |
| Tests pass alone but fail together | Shared mutable state leaking between tests | Reset state in afterEach; avoid module-level variables; use jest.isolateModules() |
| Snapshot mismatch on first run | No existing snapshot baseline | Run with --updateSnapshot on first execution to create the baseline |
Jest test for a string utility:
import { slugify } from '../src/utils/slugify';
describe('slugify', () => {
it('converts spaces to hyphens', () => {
expect(slugify('hello world')).toBe('hello-world');
});
it('lowercases all characters', () => {
expect(slugify('Hello World')).toBe('hello-world');
});
it('removes special characters', () => {
expect(slugify('hello@world!')).toBe('helloworld');
});
it('handles empty string', () => {
expect(slugify('')).toBe('');
});
it('trims leading and trailing whitespace', () => {
expect(slugify(' spaced ')).toBe('spaced');
});
});
pytest test for a data validator:
import pytest
from myapp.validators import validate_email
class TestValidateEmail:
def test_accepts_valid_email(self):
assert validate_email("user@example.com") is True
def test_rejects_missing_at_sign(self):
assert validate_email("userexample.com") is False
def test_rejects_empty_string(self):
assert validate_email("") is False
def test_rejects_none(self):
with pytest.raises(TypeError):
validate_email(None)