â ã¹ãã«äžèŠ§ã«æ»ã

test-generator
by ShunsukeHayashi
ð€ First open-source, economically-governed, beginner-friendly autonomous development framework built on Issue-Driven Development | è¶ åå¿è ã§ã䜿ããèªåŸåéçºãã¬ãŒã ã¯ãŒã¯
â 13ðŽ 8ð
2026幎1æ24æ¥
SKILL.md
name: test-generator description: Generate comprehensive unit tests for code. Use when creating tests, improving test coverage, or setting up testing frameworks. allowed-tools: Bash, Read, Write, Grep, Glob
Test Generator
Version: 1.0.0 Purpose: Generate comprehensive tests with high coverage
Triggers
| Trigger | Examples |
|---|---|
| Test creation | "write tests", "ãã¹ãäœæ", "add unit tests" |
| Coverage | "improve coverage", "ã«ãã¬ããžåäž" |
| TDD | "test first", "TDDã§" |
Testing Stack
| Framework | Purpose |
|---|---|
| Vitest | Unit/Integration tests |
| Playwright | E2E tests |
| Testing Library | Component tests |
Test Structure (AAA Pattern)
describe('functionName', () => {
it('should [expected behavior] when [condition]', () => {
// Arrange
const input = createTestInput();
// Act
const result = functionName(input);
// Assert
expect(result).toBe(expectedValue);
});
});
Test Categories
1. Happy Path
it('should return sum when given valid numbers', () => {
expect(add(2, 3)).toBe(5);
});
2. Edge Cases
it('should handle empty array', () => {
expect(sum([])).toBe(0);
});
it('should handle single element', () => {
expect(sum([5])).toBe(5);
});
it('should handle negative numbers', () => {
expect(sum([-1, 1])).toBe(0);
});
3. Error Cases
it('should throw on invalid input', () => {
expect(() => divide(10, 0)).toThrow('Division by zero');
});
it('should throw on null input', () => {
expect(() => process(null)).toThrow(TypeError);
});
4. Async Tests
it('should fetch user data', async () => {
const user = await fetchUser(1);
expect(user.name).toBe('John');
});
it('should handle API errors', async () => {
await expect(fetchUser(-1)).rejects.toThrow('Not found');
});
Mocking
Mock Functions
import { vi } from 'vitest';
const mockFn = vi.fn();
mockFn.mockReturnValue(42);
mockFn.mockResolvedValue({ data: 'test' });
Mock Modules
vi.mock('./database', () => ({
query: vi.fn().mockResolvedValue([{ id: 1 }]),
}));
Spies
const spy = vi.spyOn(console, 'log');
doSomething();
expect(spy).toHaveBeenCalledWith('expected message');
Coverage Requirements
| Metric | Target |
|---|---|
| Statements | 80% |
| Branches | 80% |
| Functions | 80% |
| Lines | 80% |
# Run with coverage
npm test -- --coverage
Test File Naming
src/
âââ utils/
â âââ helper.ts
â âââ helper.test.ts # Co-located
âââ __tests__/
âââ integration.test.ts # Integration tests
Template
import { describe, it, expect, beforeEach, vi } from 'vitest';
import { functionName } from './module';
describe('functionName', () => {
beforeEach(() => {
vi.clearAllMocks();
});
describe('when input is valid', () => {
it('should return expected result', () => {
// Arrange
const input = { /* ... */ };
// Act
const result = functionName(input);
// Assert
expect(result).toEqual(expected);
});
});
describe('when input is invalid', () => {
it('should throw error', () => {
expect(() => functionName(null)).toThrow();
});
});
describe('edge cases', () => {
it.each([
[[], 0],
[[1], 1],
[[1, 2], 3],
])('sum(%j) = %i', (input, expected) => {
expect(sum(input)).toBe(expected);
});
});
});
Checklist
- All public functions have tests
- Happy path covered
- Edge cases covered
- Error cases covered
- Async behavior tested
- Mocks properly cleaned up
- Coverage meets threshold
ã¹ã³ã¢
ç·åã¹ã³ã¢
75/100
ãªããžããªã®åè³ªææšã«åºã¥ãè©äŸ¡
âSKILL.md
SKILL.mdãã¡ã€ã«ãå«ãŸããŠãã
+20
âLICENSE
ã©ã€ã»ã³ã¹ãèšå®ãããŠãã
+10
â説ææ
100æå以äžã®èª¬æããã
+10
â人æ°
GitHub Stars 100以äž
0/15
âæè¿ã®æŽ»å
3ã¶æä»¥å ã«æŽæ°
+5
âãã©ãŒã¯
10å以äžãã©ãŒã¯ãããŠãã
0/5
âIssue管ç
ãªãŒãã³Issueã50æªæº
+5
âèšèª
ããã°ã©ãã³ã°èšèªãèšå®ãããŠãã
+5
âã¿ã°
1ã€ä»¥äžã®ã¿ã°ãèšå®ãããŠãã
+5
ã¬ãã¥ãŒ
ð¬
ã¬ãã¥ãŒæ©èœã¯è¿æ¥å ¬éäºå®ã§ã

