Generate unit tests, integration tests, and test fixtures for code. Supports Jest, Mocha, pytest. Use when writing tests or improving test coverage. This skill provides automated test generation: - Unit tests with AAA pattern (Arrange, Act, Assert) - Integration tests for APIs and databases - Test fixtures and mocks - Edge case identification - Test coverage recommendations Triggers: "generate tests", "create unit test", "add test coverage", "write tests", "テスト生成", "テストコード作成", "カバレッジ向上"
Automatically generates unit tests, integration tests, and fixtures for Jest, Mocha, and pytest. Triggers when you request test creation or coverage improvement for existing code.
/plugin marketplace add takemi-ohama/ai-agent-marketplace/plugin install ndf@ai-agent-marketplaceThis skill is limited to using the following tools:
このSkillは、corderエージェントが既存のコードに対してテストを自動生成する際に使用します。Jest、Mocha、pytestなどの主要なテストフレームワークに対応し、ユニットテスト、統合テスト、テストフィクスチャを生成します。
templates/
├── jest-unit-test.test.js # Jest ユニットテスト
├── mocha-test.test.js # Mocha テスト
├── pytest-test.py # pytest
├── test-fixtures.json # テストデータ
└── integration-test.test.js # 統合テスト
1. 既存関数のユニットテスト生成
// 元のコード: src/utils/calculator.js
function add(a, b) {
return a + b;
}
function divide(a, b) {
if (b === 0) {
throw new Error('Division by zero');
}
return a / b;
}
module.exports = { add, divide };
生成されるテスト:
// tests/utils/calculator.test.js
const { add, divide } = require('../../src/utils/calculator');
describe('calculator', () => {
describe('add', () => {
test('should add two positive numbers', () => {
// Arrange
const a = 2;
const b = 3;
const expected = 5;
// Act
const result = add(a, b);
// Assert
expect(result).toBe(expected);
});
test('should handle negative numbers', () => {
expect(add(-2, -3)).toBe(-5);
});
test('should handle zero', () => {
expect(add(0, 5)).toBe(5);
expect(add(5, 0)).toBe(5);
});
});
describe('divide', () => {
test('should divide two numbers', () => {
expect(divide(10, 2)).toBe(5);
});
test('should throw error when dividing by zero', () => {
expect(() => divide(10, 0)).toThrow('Division by zero');
});
test('should handle negative numbers', () => {
expect(divide(-10, 2)).toBe(-5);
});
});
});
2. API統合テスト生成
// tests/api/users.integration.test.js
const request = require('supertest');
const app = require('../../app');
const db = require('../../models');
describe('Users API', () => {
beforeAll(async () => {
await db.sequelize.sync({ force: true });
});
afterAll(async () => {
await db.sequelize.close();
});
describe('GET /api/users', () => {
test('should return all users', async () => {
const response = await request(app)
.get('/api/users')
.expect('Content-Type', /json/)
.expect(200);
expect(response.body.success).toBe(true);
expect(Array.isArray(response.body.data)).toBe(true);
});
test('should support pagination', async () => {
const response = await request(app)
.get('/api/users?page=1&limit=10')
.expect(200);
expect(response.body.pagination).toBeDefined();
expect(response.body.pagination.page).toBe(1);
expect(response.body.pagination.limit).toBe(10);
});
});
describe('POST /api/users', () => {
test('should create new user', async () => {
const newUser = {
name: 'Test User',
email: 'test@example.com'
};
const response = await request(app)
.post('/api/users')
.send(newUser)
.expect(201);
expect(response.body.success).toBe(true);
expect(response.body.data.name).toBe(newUser.name);
});
test('should return 400 for invalid data', async () => {
const invalidUser = {
name: 'A', // Too short
email: 'invalid-email'
};
const response = await request(app)
.post('/api/users')
.send(invalidUser)
.expect(400);
expect(response.body.success).toBe(false);
expect(response.body.errors).toBeDefined();
});
});
});
既存のコードを解析し、テストケースのスケルトンを自動生成します。
使用方法:
node scripts/generate-tests.js src/utils/calculator.js
機能:
test('should do something', () => {
// Arrange: テストデータを準備
const input = { ... };
const expected = { ... };
// Act: テスト対象を実行
const result = functionUnderTest(input);
// Assert: 結果を検証
expect(result).toEqual(expected);
});
describe('edge cases', () => {
test('should handle null input', () => {
expect(() => func(null)).toThrow();
});
test('should handle empty array', () => {
expect(func([])).toEqual([]);
});
test('should handle boundary values', () => {
expect(func(0)).toBe(...);
expect(func(-1)).toBe(...);
expect(func(Number.MAX_VALUE)).toBe(...);
});
});
test('should call API', async () => {
// モック作成
const mockFetch = jest.fn().mockResolvedValue({
json: () => ({ data: 'test' })
});
global.fetch = mockFetch;
// 実行
await fetchData();
// 検証
expect(mockFetch).toHaveBeenCalledWith('/api/data');
expect(mockFetch).toHaveBeenCalledTimes(1);
});
✅ AAAパターンに従う: テストの可読性向上 ✅ 1テスト = 1アサーション: テストの意図を明確に ✅ エッジケースをテスト: null、empty、boundary値 ✅ 独立したテスト: 実行順序に依存しない ✅ わかりやすいテスト名: 何をテストするか明示
❌ テストの重複: 同じことを複数回テストしない ❌ 実装の詳細に依存: 内部変数名等に依存しない ❌ 過剰なモック: 必要最小限にとどめる ❌ 外部依存: ネットワーク、データベースはモック ❌ テストのテスト: テストコード自体はテストしない
このSKILL.mdはメインドキュメント(約250行)です。詳細なテンプレートとスクリプトは templates/, scripts/ ディレクトリ内のファイルを参照してください。
This skill should be used when the user asks to "create a slash command", "add a command", "write a custom command", "define command arguments", "use command frontmatter", "organize commands", "create command with file references", "interactive command", "use AskUserQuestion in command", or needs guidance on slash command structure, YAML frontmatter fields, dynamic arguments, bash execution in commands, user interaction patterns, or command development best practices for Claude Code.
This skill should be used when the user asks to "create an agent", "add an agent", "write a subagent", "agent frontmatter", "when to use description", "agent examples", "agent tools", "agent colors", "autonomous agent", or needs guidance on agent structure, system prompts, triggering conditions, or agent development best practices for Claude Code plugins.
This skill should be used when the user asks to "create a hook", "add a PreToolUse/PostToolUse/Stop hook", "validate tool use", "implement prompt-based hooks", "use ${CLAUDE_PLUGIN_ROOT}", "set up event-driven automation", "block dangerous commands", or mentions hook events (PreToolUse, PostToolUse, Stop, SubagentStop, SessionStart, SessionEnd, UserPromptSubmit, PreCompact, Notification). Provides comprehensive guidance for creating and implementing Claude Code plugin hooks with focus on advanced prompt-based hooks API.