name: “QE测试生成” description: “使用模式识别、代码分析和智能测试合成的AI驱动测试生成,以实现全面测试覆盖。” trust_tier: 3 validation: schema_path: schemas/output.json validator_path: scripts/validate-config.json eval_path: evals/qe-test-generation.yaml
QE测试生成
目的
指导使用v3的AI驱动测试生成能力,包括基于模式的测试合成、多框架支持和从代码分析中智能推导测试用例。
激活时机
- 为新代码生成测试时
- 当改进测试覆盖率时
- 在框架间迁移测试时
- 应用TDD模式时
- 生成边缘案例测试时
快速开始
# 为文件生成单元测试
aqe test generate --file src/services/UserService.ts --framework jest
# 生成具有覆盖率目标的测试
aqe test generate --scope src/api/ --coverage 90 --type unit
# 生成集成测试
aqe test generate --file src/controllers/AuthController.ts --type integration
# 从模式生成
aqe test generate --pattern repository --target src/repositories/
代理工作流
// 生成测试生成代理
Task("生成单元测试", `
分析 src/services/PaymentService.ts 并生成全面的Jest测试。
包括:
- 所有公共方法的快乐路径测试
- 边缘案例和边界条件
- 错误处理场景
- 模拟外部依赖
输出到 tests/unit/services/PaymentService.test.ts
`, "qe-test-generator")
// 基于模式的生成
Task("应用测试模式", `
扫描 src/repositories/ 并应用仓库测试模式:
- CRUD操作测试
- 查询构建器测试
- 事务测试
- 连接错误处理
`, "qe-pattern-matcher")
测试生成策略
1. 基于代码分析
await testGenerator.analyzeAndGenerate({
source: 'src/services/OrderService.ts',
analysis: {
methods: true,
branches: true,
dependencies: true,
errorPaths: true
},
output: {
framework: 'jest',
style: 'describe-it',
assertions: 'expect'
}
});
2. 基于模式的生成
await testGenerator.applyPattern({
pattern: 'service-layer',
targets: ['src/services/*.ts'],
customizations: {
mockStrategy: 'jest.mock',
asyncHandling: 'async-await',
errorAssertion: 'toThrow'
}
});
3. 覆盖率驱动生成
await testGenerator.fillCoverageGaps({
coverageReport: 'coverage/lcov.info',
targetCoverage: 90,
prioritize: ['uncovered-branches', 'error-paths'],
maxTests: 50
});
框架支持
| 框架 | 单元 | 集成 | E2E | 模拟 |
|---|---|---|---|---|
| Jest | ✅ | ✅ | ⚠️ | jest.mock |
| Vitest | ✅ | ✅ | ⚠️ | vi.mock |
| Mocha | ✅ | ✅ | ❌ | sinon |
| Pytest | ✅ | ✅ | ❌ | pytest-mock |
| JUnit | ✅ | ✅ | ❌ | Mockito |
测试质量检查
quality_checks:
assertions:
minimum_per_test: 1
meaningful: true
isolation:
no_shared_state: true
proper_setup_teardown: true
naming:
descriptive: true
follows_convention: true
coverage:
branches: 80
statements: 85
协调
主要代理: qe-test-generator, qe-pattern-matcher, qe-test-architect 协调器: qe-test-generation-coordinator 相关技能: qe-coverage-analysis, qe-test-execution