test-generator by oimiragieo/agent-studio
npx skills add https://github.com/oimiragieo/agent-studio --skill test-generator模式:认知/提示驱动 — 无独立实用脚本;通过代理上下文使用。
确定需要哪种类型的测试:
检查待测试的代码(使用并行读取/Grep/Glob):
审查现有测试:
按照模式创建测试:
生成测试后,分析覆盖率:
检查生成的测试是否覆盖所有需求:
:
广告位招租
在这里展示您的产品或服务
触达数万 AI 开发者,精准高效
报告覆盖率百分比:
覆盖率验证清单:
<code_example> 单元测试 (React/Vitest)
import { render, screen, waitFor } from '@testing-library/react'
import { describe, it, expect, vi } from 'vitest'
import { UserProfile } from './user-profile'
describe('UserProfile', () => {
it('renders user information', async () => {
const mockUser = { id: '1', name: 'John', email: 'john@example.com' }
render(<UserProfile user={mockUser} />)
await waitFor(() => {
expect(screen.getByText('John')).toBeInTheDocument()
expect(screen.getByText('john@example.com')).toBeInTheDocument()
})
})
it('handles loading state', () => {
render(<UserProfile user={null} loading />)
expect(screen.getByTestId('loading')).toBeInTheDocument()
})
it('handles error state', () => {
render(<UserProfile user={null} error="Failed to load" />)
expect(screen.getByText('Failed to load')).toBeInTheDocument()
})
})
</code_example>
<code_example> 集成测试 (API)
import { describe, it, expect, beforeAll, afterAll } from 'vitest';
import { createTestClient } from './test-client';
describe('Users API', () => {
let client: TestClient;
beforeAll(() => {
client = createTestClient();
});
afterAll(async () => {
await client.cleanup();
});
it('creates a user', async () => {
const response = await client.post('/api/users', {
email: 'test@example.com',
name: 'Test User',
});
expect(response.status).toBe(201);
expect(response.data).toHaveProperty('id');
expect(response.data.email).toBe('test@example.com');
});
it('validates required fields', async () => {
const response = await client.post('/api/users', {});
expect(response.status).toBe(400);
expect(response.data).toHaveProperty('errors');
});
});
</code_example>
<code_example> 端到端测试 (Cypress)
describe('User Authentication Flow', () => {
beforeEach(() => {
cy.visit('/login');
});
it('allows user to login', () => {
cy.get('[data-testid="email-input"]').type('user@example.com');
cy.get('[data-testid="password-input"]').type('password123');
cy.get('[data-testid="login-button"]').click();
cy.url().should('include', '/dashboard');
cy.get('[data-testid="user-menu"]').should('be.visible');
});
it('shows error for invalid credentials', () => {
cy.get('[data-testid="email-input"]').type('invalid@example.com');
cy.get('[data-testid="password-input"]').type('wrong');
cy.get('[data-testid="login-button"]').click();
cy.get('[data-testid="error-message"]')
.should('be.visible')
.and('contain', 'Invalid credentials');
});
});
</code_example>
与 QA 代理集成:
<best_practices>
<usage_example>
# 为文件生成测试
node .claude/skills/test-generator/scripts/main.cjs src/components/UserProfile.tsx
# 该工具将分析文件并生成适当的测试
</usage_example>
| 反模式 | 失败原因 | 正确方法 |
|---|---|---|
| 测试实现细节 | 即使行为未变,重构时也会中断 | 测试公共 API 行为和可观察的输出 |
| 测试体中没有断言 | 测试总是通过,无法捕获任何问题 | 为每个测试用例添加明确的断言 |
| 测试间共享可变状态 | 测试失败取决于执行顺序 | 使用 beforeEach/afterEach 实现完全隔离 |
| 断言中使用魔术数字 | 预期值不明确,测试脆弱 | 使用命名常量或描述性的固定数据 |
| 缺少错误路径测试 | 覆盖率不足,生产环境静默失败 | 同时测试成功和失败场景 |
开始前: 阅读 .claude/context/memory/learnings.md
完成后:
.claude/context/memory/learnings.md.claude/context/memory/issues.md.claude/context/memory/decisions.md假设中断:如果不在内存中,就视为未发生。
每周安装次数
78
代码仓库
GitHub 星标数
17
首次出现
2026年1月27日
安全审计
安装于
github-copilot75
opencode74
gemini-cli74
kimi-cli73
amp73
codex73
Mode: Cognitive/Prompt-Driven — No standalone utility script; use via agent context.
Determine what type of test is needed:
Examine code to test (Use Parallel Read/Grep/Glob):
Review existing tests:
Create test following patterns:
After generating tests, analyze coverage:
Check that generated tests cover all requirements :
Validate tests are runnable :
Report coverage percentage :
Coverage Validation Checklist :
import { render, screen, waitFor } from '@testing-library/react'
import { describe, it, expect, vi } from 'vitest'
import { UserProfile } from './user-profile'
describe('UserProfile', () => {
it('renders user information', async () => {
const mockUser = { id: '1', name: 'John', email: 'john@example.com' }
render(<UserProfile user={mockUser} />)
await waitFor(() => {
expect(screen.getByText('John')).toBeInTheDocument()
expect(screen.getByText('john@example.com')).toBeInTheDocument()
})
})
it('handles loading state', () => {
render(<UserProfile user={null} loading />)
expect(screen.getByTestId('loading')).toBeInTheDocument()
})
it('handles error state', () => {
render(<UserProfile user={null} error="Failed to load" />)
expect(screen.getByText('Failed to load')).toBeInTheDocument()
})
})
</code_example>
<code_example> Integration Test (API)
import { describe, it, expect, beforeAll, afterAll } from 'vitest';
import { createTestClient } from './test-client';
describe('Users API', () => {
let client: TestClient;
beforeAll(() => {
client = createTestClient();
});
afterAll(async () => {
await client.cleanup();
});
it('creates a user', async () => {
const response = await client.post('/api/users', {
email: 'test@example.com',
name: 'Test User',
});
expect(response.status).toBe(201);
expect(response.data).toHaveProperty('id');
expect(response.data.email).toBe('test@example.com');
});
it('validates required fields', async () => {
const response = await client.post('/api/users', {});
expect(response.status).toBe(400);
expect(response.data).toHaveProperty('errors');
});
});
</code_example>
<code_example> E2E Test (Cypress)
describe('User Authentication Flow', () => {
beforeEach(() => {
cy.visit('/login');
});
it('allows user to login', () => {
cy.get('[data-testid="email-input"]').type('user@example.com');
cy.get('[data-testid="password-input"]').type('password123');
cy.get('[data-testid="login-button"]').click();
cy.url().should('include', '/dashboard');
cy.get('[data-testid="user-menu"]').should('be.visible');
});
it('shows error for invalid credentials', () => {
cy.get('[data-testid="email-input"]').type('invalid@example.com');
cy.get('[data-testid="password-input"]').type('wrong');
cy.get('[data-testid="login-button"]').click();
cy.get('[data-testid="error-message"]')
.should('be.visible')
.and('contain', 'Invalid credentials');
});
});
</code_example>
Integration with QA Agent :
<best_practices>
# Generate tests for a file
node .claude/skills/test-generator/scripts/main.cjs src/components/UserProfile.tsx
# The tool will analyze the file and generate appropriate tests
</usage_example>
| Anti-Pattern | Why It Fails | Correct Approach |
|---|---|---|
| Testing implementation details | Breaks on refactor even when behavior is unchanged | Test public API behavior and observable outputs |
| No assertions in test body | Test always passes, catches nothing | Add explicit assertions for every test case |
| Shared mutable state between tests | Tests fail depending on execution order | Use beforeEach/afterEach for full isolation |
| Magic numbers in assertions | Unclear expected values, brittle tests | Use named constants or descriptive fixture data |
| Missing error path tests | Half coverage, silent failures in production | Test both success and failure scenarios |
Before starting: Read .claude/context/memory/learnings.md
After completing:
.claude/context/memory/learnings.md.claude/context/memory/issues.md.claude/context/memory/decisions.mdASSUME INTERRUPTION: If it's not in memory, it didn't happen.
Weekly Installs
78
Repository
GitHub Stars
17
First Seen
Jan 27, 2026
Security Audits
Gen Agent Trust HubPassSocketPassSnykPass
Installed on
github-copilot75
opencode74
gemini-cli74
kimi-cli73
amp73
codex73
Skills CLI 使用指南:AI Agent 技能包管理器安装与管理教程
44,900 周安装