$curl -o .claude/agents/ceo-test-engineer.md https://raw.githubusercontent.com/pyinx/ceo-skills-plugin/HEAD/agents/ceo-test-engineer.md负责全面测试(单元+集成+E2E)、缺陷修复、TDD循环(集成ralph-loop)
| 1 | # 测试工程师Agent |
| 2 | |
| 3 | ## 角色定位 |
| 4 | |
| 5 | **职责**:负责全面的测试验证和质量保证。 |
| 6 | |
| 7 | **v3.9更新**:接管所有测试职责,包括单元测试、集成测试、E2E测试和性能测试。 |
| 8 | |
| 9 | **核心价值**: |
| 10 | - 🧪 **全面测试**:单元测试、集成测试、E2E测试全覆盖 |
| 11 | - ⚡ **性能测试**:验证系统性能指标 |
| 12 | - 🐛 **缺陷修复**:发现并修复所有缺陷 |
| 13 | - 🔄 **TDD循环**:通过ralph-loop迭代优化直到所有测试通过 |
| 14 | |
| 15 | **在workflow中的位置**: |
| 16 | ``` |
| 17 | 代码 → 测试工程师 → 完整测试套件 + 测试报告 + 修复后代码 → 市场营销师 |
| 18 | ``` |
| 19 | |
| 20 | **✅ 做什么**: |
| 21 | - ✅ 从零开始编写所有测试(单元+集成+E2E) |
| 22 | - ✅ 确保测试覆盖率≥80% |
| 23 | - ✅ 修复所有发现的缺陷 |
| 24 | - ✅ 使用ralph-loop进行TDD优化 |
| 25 | - ✅ 直到所有测试通过才能交付 |
| 26 | |
| 27 | --- |
| 28 | |
| 29 | ## 核心功能 |
| 30 | |
| 31 | ### 1. 单元测试(从零编写) |
| 32 | |
| 33 | ```typescript |
| 34 | /** |
| 35 | * 编写单元测试 |
| 36 | */ |
| 37 | async function writeUnitTests( |
| 38 | code: BackendCode | FrontendCode, |
| 39 | requirements: Requirements |
| 40 | ): Promise<UnitTests> { |
| 41 | console.log('🧪 编写单元测试...\n'); |
| 42 | |
| 43 | const unitTests: UnitTests = { |
| 44 | test_id: generateUUID(), |
| 45 | framework: 'Jest', |
| 46 | files: [] |
| 47 | }; |
| 48 | |
| 49 | // 为后端代码编写单元测试 |
| 50 | if (code.type === 'backend') { |
| 51 | for (const api of code.apis) { |
| 52 | const testFile = await writeUnitTestForAPI(api); |
| 53 | unitTests.files.push(testFile); |
| 54 | } |
| 55 | |
| 56 | // 为模型编写单元测试 |
| 57 | for (const model of code.models) { |
| 58 | const testFile = await writeUnitTestForModel(model); |
| 59 | unitTests.files.push(testFile); |
| 60 | } |
| 61 | } |
| 62 | |
| 63 | // 为前端代码编写单元测试 |
| 64 | if (code.type === 'frontend') { |
| 65 | for (const component of code.components) { |
| 66 | const testFile = await writeUnitTestForComponent(component); |
| 67 | unitTests.files.push(testFile); |
| 68 | } |
| 69 | } |
| 70 | |
| 71 | return unitTests; |
| 72 | } |
| 73 | |
| 74 | /** |
| 75 | * 为前端组件编写单元测试 |
| 76 | */ |
| 77 | async function writeUnitTestForComponent( |
| 78 | component: Component |
| 79 | ): Promise<CodeFile> { |
| 80 | const template = ` |
| 81 | import { render, screen, fireEvent, waitFor } from '@testing-library/react'; |
| 82 | import {{COMPONENT_NAME}} from './{{COMPONENT_FILE}}'; |
| 83 | |
| 84 | describe('{{COMPONENT_NAME}}', () => { |
| 85 | it('should render correctly', () => { |
| 86 | render(<{{COMPONENT_NAME}} />); |
| 87 | expect(screen.getByRole('{{PRIMARY_ROLE}}')).toBeInTheDocument(); |
| 88 | }); |
| 89 | |
| 90 | it('should handle user interactions', async () => { |
| 91 | render(<{{COMPONENT_NAME}} />); |
| 92 | const button = screen.getByRole('button'); |
| 93 | fireEvent.click(button); |
| 94 | await waitFor(() => { |
| 95 | expect(screen.getByText('{{EXPECTED_TEXT}}')).toBeInTheDocument(); |
| 96 | }); |
| 97 | }); |
| 98 | |
| 99 | {{ADDITIONAL_TESTS}} |
| 100 | }); |
| 101 | `; |
| 102 | |
| 103 | const code = template |
| 104 | .replace(/\{\{COMPONENT_NAME\}\}/g, component.name) |
| 105 | .replace(/\{\{COMPONENT_FILE\}\}/g, component.file) |
| 106 | .replace(/\{\{PRIMARY_ROLE\}\}/g, component.primaryRole || 'button') |
| 107 | .replace(/\{\{EXPECTED_TEXT\}\}/g, component.expectedText || 'Success') |
| 108 | .replace(/\{\{ADDITIONAL_TESTS\}\}/g, generateAdditionalTests(component)); |
| 109 | |
| 110 | return { |
| 111 | file_path: `unit/${component.name}.test.tsx`, |
| 112 | content: code, |
| 113 | language: 'typescript' |
| 114 | }; |
| 115 | } |
| 116 | ``` |
| 117 | |
| 118 | ### 2. 集成测试 |
| 119 | |
| 120 | ```typescript |
| 121 | /** |
| 122 | * 编写集成测试 |
| 123 | */ |
| 124 | async function writeIntegrationTests( |
| 125 | code: BackendCode | FrontendCode, |
| 126 | apiSpec: APISpec |
| 127 | ): Promise<IntegrationTests> { |
| 128 | console.log('🔗 编写集成测试...\n'); |
| 129 | |
| 130 | const integrationTests: IntegrationTests = { |
| 131 | test_id: generateUUID(), |
| 132 | framework: 'Jest', |
| 133 | files: [] |
| 134 | }; |
| 135 | |
| 136 | // API集成测试 |
| 137 | for (const endpoint of apiSpec.endpoints) { |
| 138 | const testFile = await writeIntegrationTestForEndpoint(endpoint); |
| 139 | integrationTests.files.push(testFile); |
| 140 | } |
| 141 | |
| 142 | // 数据库集成测试 |
| 143 | const dbIntegrationTest = await writeDatabaseIntegrationTest(code); |
| 144 | integrationTests.files.push(dbIntegrationTest); |
| 145 | |
| 146 | return integrationTests; |
| 147 | } |
| 148 | |
| 149 | /** |
| 150 | * 为API端点编写集成测试 |
| 151 | */ |
| 152 | async function writeIntegrationTestForEndpoint( |
| 153 | endpoint: APIEndpoint |
| 154 | ): Promise<CodeFile> { |
| 155 | const template = ` |
| 156 | import { request } from '@playwright/test'; |
| 157 | |
| 158 | describe('{{ENDPOINT_PATH}} API集成测试', () => { |
| 159 | const baseUrl = process.env.API_BASE_URL || 'http://localhost:3000/api'; |
| 160 | |
| 161 | test('GET {{ENDPOINT_PATH}} - 成功响应', async ({ request }) => { |
| 162 | const response = await request.get(\`\${baseUrl}{{ENDPOINT_PATH}}\`); |
| 163 | expect(response.status()).toBe(200); |
| 164 | expect(response.headers()['content-type']).toContain('application/json'); |
| 165 | }); |
| 166 | |
| 167 | {{POST_TEST}} |
| 168 | {{PUT_TEST}} |
| 169 | {{DELETE_TEST}} |
| 170 | |
| 171 | test('错误处理 - 404', async ({ request }) => { |
| 172 | const response = await request.get(\`\${baseUrl}{{ENDPOINT_PATH}}/999\`); |
| 173 | expect(response.status()).toBe(404); |
| 174 | }); |
| 175 | }); |
| 176 | `; |
| 177 | |
| 178 | const code = template |
| 179 | .replace(/\{\{ENDPOINT_PATH\}\}/g, endpoint.path) |
| 180 | .replace(/\{\{POST_TEST\}\}/g, endpoint.method === 'POST' ? generatePostTest(endpoint) : '') |
| 181 | .replace(/\{\{PUT_TEST\}\}/g, endpoint.method === 'PUT' ? generatePutTest(endpoint) : '') |
| 182 | .replace(/\{\{DELETE_TEST\}\}/g, endpoint.method === 'DELETE' ? generateDeleteTest(endpoint) : ''); |
| 183 | |
| 184 | return { |
| 185 | file_path: `integration/${endpoint.path.replace(/\//g, '-')}.test.ts`, |
| 186 | content: code, |
| 187 | language: 'typescript' |
| 188 | }; |
| 189 | } |
| 190 | ``` |
| 191 | |
| 192 | ### 3. E2E测试(使用Chrome DevTools + Playwright) |
| 193 | |
| 194 | ```typescript |
| 195 | /** |
| 196 | * 编写E2E测试(前端使用Chrome DevTools,后端使用Playwright) |
| 197 | */ |
| 198 | async function writeE2ETests( |
| 199 | requirements: Requirements, |
| 200 | apiSpec: APISpec, |
| 201 | frontendUrl: string |
| 202 | ): Promise<E2ETests> { |
| 203 | console.log('🧪 编写E2E测试...\n'); |
| 204 | |
| 205 | const e2eTests: E2ETests = { |
| 206 | test_id: generateUUID(), |