名称: “QE测试执行” 描述: “带有智能调度、重试逻辑和全面结果聚合的并行测试执行编排。” 信任等级: 3 验证: schema_path: schemas/output.json validator_path: scripts/validate-config.json eval_path: evals/qe-test-execution.yaml
QE测试执行
目的
指导使用v3的测试执行能力,包括并行编排、智能测试选择、不稳定测试处理和跨多个环境的分布式执行。
激活时机
- 当运行测试套件时
- 当优化测试执行时间时
- 当处理不稳定测试时
- 当设置CI/CD测试管道时
- 当跨环境执行测试时
快速开始
# 使用并行化运行所有测试
aqe test run --parallel --workers 4
# 仅运行受影响的测试
aqe test run --affected --since HEAD~1
# 运行并重试不稳定测试
aqe test run --retry 3 --retry-delay 1000
# 运行特定测试类型
aqe test run --type unit,integration --exclude e2e
代理工作流
// 编排测试执行
Task("执行测试套件", `
使用以下方式运行完整测试套件:
- 4个并行工作器
- 重试不稳定测试最多3次
- 生成JUnit报告
- 对关键测试快速失败
报告结果和任何失败。
`, "qe-test-executor")
// 智能测试选择
Task("运行受影响的测试", `
分析PR #123中的更改,并:
- 识别受影响的测试文件
- 仅运行相关测试
- 包括更改模块的集成测试
- 报告覆盖率差异
`, "qe-test-selector")
执行策略
1. 并行执行
await testExecutor.runParallel({
suites: ['unit', 'integration'],
workers: 4,
distribution: 'by-file', // 或 'by-test', 'by-duration'
isolation: 'process',
sharding: {
enabled: true,
total: 4,
index: process.env.SHARD_INDEX
}
});
2. 智能测试选择
await testExecutor.runAffected({
changes: gitChanges,
selection: {
direct: true, // 针对更改文件的测试
transitive: true, // 针对依赖项的测试
integration: true // 触及更改代码的集成测试
},
fallback: 'full-suite' // 如果分析失败
});
3. 不稳定测试处理
await testExecutor.handleFlaky({
detection: {
enabled: true,
threshold: 0.1, // 10%的不稳定率
window: 100 // 最近100次运行
},
strategy: {
retry: 3,
quarantine: true,
notify: ['#flaky-tests']
}
});
执行配置
execution:
parallel:
workers: auto # CPU核心数 - 1
timeout: 30000
bail: false
retry:
count: 2
delay: 1000
only_failed: true
reporting:
formats: [junit, json, html]
include_timing: true
include_logs: true
environments:
- name: node-18
image: node:18-alpine
- name: node-20
image: node:20-alpine
CI/CD集成
# GitHub Actions示例
test:
runs-on: ubuntu-latest
strategy:
matrix:
shard: [1, 2, 3, 4]
steps:
- uses: actions/checkout@v4
- name: 运行测试
run: |
aqe test run \
--shard ${{ matrix.shard }}/4 \
--parallel \
--report junit
- name: 上传结果
uses: actions/upload-artifact@v4
with:
name: test-results-${{ matrix.shard }}
path: reports/
结果聚合
interface ExecutionResults {
summary: {
total: number;
passed: number;
failed: number;
skipped: number;
flaky: number;
duration: number;
};
shards: ShardResult[];
failures: TestFailure[];
flakyTests: FlakyTest[];
coverage: CoverageReport;
timing: TimingAnalysis;
}
协调
主要代理: qe-test-executor, qe-test-selector, qe-flaky-detector 协调器: qe-test-execution-coordinator 相关技能: qe-test-generation, qe-coverage-analysis