mcpField
T
test-automation-strategy

test-automation-strategy

github.com/proffesor-for-testing测试与质量519254 次安装今天更新
代码仓库

关于 test-automation-strategy

面向构建或改进自动化测试套件团队的策略技能,介绍测试结构模式、CI/CD 集成,以及处理运行缓慢、脆弱或不稳定测试的方法。

主要功能

  1. 01识别常见自动化反模式
  2. 02采用 Page Object、Builder 和 Factory 模式
  3. 03将测试集成到 CI/CD
  4. 04隔离并稳定不可靠测试
  5. 05倡导单元、集成与端到端测试金字塔

适用场景

  1. 01设计新的自动化测试框架
  2. 02改进运行缓慢的测试套件
  3. 03减少随机测试失败
  4. 04加快 CI/CD 流水线

安装

复制下面的命令,在终端中运行。

$npx skills add https://github.com/proffesor-for-testing/agentic-qe --skill test-automation-strategy

安装后在 Claude Code 中输入/test-automation-strategy确认已加载。

包含的文件

除 SKILL.md 外,安装时一起下载的参考资料和脚本。

evals/
test-automation-strategy.yaml
schemas/
output.json
scripts/
validate-config.json

详细介绍

测试自动化策略

<default_to_action> 设计或改进测试自动化时:

  1. 检测反模式:冰淇淋筒?测试套件运行缓慢?测试不稳定?
  2. 使用模式:页面对象模型、构建器模式、工厂模式
  3. 集成到 CI/CD:每次提交都运行测试,快速失败
  4. 管理不稳定的测试:隔离、修复或删除,绝不忽略

快速检测反模式:

  • 冰淇淋筒(端到端测试很多,单元测试很少)→ 调整为金字塔结构
  • 测试运行缓慢(测试套件耗时 > 10 分钟)→ 并行运行,模拟外部依赖
  • 测试不稳定 → 修复时序问题、隔离数据或将其隔离
  • 脆弱的选择器 → 使用 data-testid、语义定位器 </default_to_action>

快速参考卡

适用场景
  • 构建新的自动化框架
  • 提高现有测试的效率
  • 减轻不稳定测试带来的负担
  • 优化 CI/CD 流水线速度
需要检测的反模式
问题症状修复方法
冰淇淋筒80% 端到端测试,10% 单元测试调整为金字塔结构
测试套件运行缓慢CI 耗时 30 分钟以上并行运行,精简测试
测试不稳定随机失败隔离,修复时序问题
测试耦合依赖执行顺序隔离数据
脆弱的选择器CSS 更改后失效使用 data-testid

CI/CD 集成

name: Test Pipeline
on: [push, pull_request]

jobs:
  unit-tests:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - run: npm ci
      - run: npm run test:unit -- --coverage
        timeout-minutes: 5
      - uses: codecov/codecov-action@v3

  integration-tests:
    needs: unit-tests
    runs-on: ubuntu-latest
    services:
      postgres:
        image: postgres:15
    steps:
      - run: npm run test:integration
        timeout-minutes: 10

  e2e-tests:
    needs: integration-tests
    runs-on: ubuntu-latest
    steps:
      - run: npx playwright test
        timeout-minutes: 15

不稳定测试管理

// Quarantine flaky tests
describe.skip('Quarantined - INC-123', () => {
  test('flaky test awaiting fix', () => { /* ... */ });
});

// Agent-assisted stabilization
await Task("Fix Flaky Tests", {
  tests: quarantinedTests,
  analysis: ['timing-issues', 'data-isolation', 'race-conditions'],
  strategies: ['add-waits', 'isolate-fixtures', 'mock-externals']
}, "qe-flaky-test-hunter");

Agent 辅助自动化

// Generate tests following pyramid
await Task("Generate Test Suite", {
  sourceCode: 'src/',
  pyramid: { unit: 70, integration: 20, e2e: 10 },
  patterns: ['page-object', 'builder', 'factory'],
  framework: 'jest'
}, "qe-test-generator");

// Optimize test execution
await Task("Optimize Suite", {
  algorithm: 'johnson-lindenstrauss',
  targetReduction: 0.3,
  maintainCoverage: 0.95
}, "qe-regression-risk-analyzer");

// Analyze flaky patterns
await Task("Flaky Analysis", {
  testHistory: 'last-30-days',
  detectPatterns: ['timing', 'data', 'environment'],
  recommend: 'stabilization-strategy'
}, "qe-flaky-test-hunter");

Agent 协作提示

记忆命名空间
aqe/automation/
├── test-pyramid/*        - Coverage by layer
├── page-objects/*        - Shared page objects
├── flaky-registry/*      - Quarantined tests
└── execution-metrics/*   - Suite performance data
集群协作
const automationFleet = await FleetManager.coordinate({
  strategy: 'test-automation',
  agents: [
    'qe-test-generator',         // Generate pyramid-compliant tests
    'qe-test-executor',          // Parallel execution
    'qe-coverage-analyzer',      // Coverage gaps
    'qe-flaky-test-hunter',      // Flaky detection
    'qe-regression-risk-analyzer' // Smart selection
  ],
  topology: 'hierarchical'
});

相关技能


请记住

使用 Agent: Agent 可生成符合金字塔结构的测试、检测不稳定模式、优化执行时间并维护测试基础设施。使用 Agent 扩展自动化质量。

注意事项

  • Agent 生成了 80% 端到端测试和 20% 单元测试(倒金字塔结构)——明确要求遵循 70/20/10 的比例
  • 当选择器更改时,页面对象模型测试会变得脆弱——优先使用 data-testid 属性,而不是 CSS 选择器
  • 不稳定测试被隔离后却从未修复,会成为技术债务——设置 2 周的 SLA,以便修复或删除
  • Agent 将测试代码视为次等代码——测试代码需要遵循与生产代码相同的审查标准
  • 并行执行测试需要隔离测试——测试间共享状态会导致非确定性失败

评论

支持 Markdown