mcpField
T
test-environment-management

test-environment-management

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

关于 test-environment-management

test-environment-management 是用于搭建和管理测试环境的技能,涵盖容器化、与生产环境保持一致、模拟外部服务,以及定时关停等成本控制方法。

主要功能

  1. 01定义环境类型
  2. 02用 Docker 保持环境可复现
  3. 03检查与生产环境的一致性
  4. 04模拟外部服务
  5. 05通过定时关停控制成本

适用场景

  1. 01搭建一致的测试基础设施
  2. 02调查特定环境下出现的故障
  3. 03在不依赖外部服务时进行测试
  4. 04管理测试基础设施成本

安装

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

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

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

附带文件schemas/output.json

详细介绍

测试环境管理

<default_to_action> 管理测试环境时:

  1. 定义环境类型(本地、CI、预发布、生产)
  2. 使用 Docker 容器化,确保一致性
  3. 确保与生产环境一致(相同版本、配置)
  4. 模拟外部服务(服务虚拟化)
  5. 优化成本(自动关闭、竞价实例)

环境快速检查清单:

  • 与生产环境使用相同的操作系统和版本
  • 使用相同的数据库类型和版本
  • 使用相同的配置结构
  • 使用容器确保可复现性
  • 数小时后自动关闭

关键成功因素:

  • “在我的机器上能运行” = 环境不一致
  • 基础设施即代码 = 可重复的环境
  • 服务虚拟化 = 无需外部依赖即可测试 </default_to_action>

快速参考卡

适用场景
  • 搭建测试基础设施
  • 调试特定环境下的故障
  • 降低测试基础设施成本
  • 确保开发环境与生产环境一致

用于测试环境的 Docker

# docker-compose.test.yml
version: '3.8'

services:
  app:
    build: .
    ports:
      - "3000:3000"
    environment:
      NODE_ENV: test
      DATABASE_URL: postgres://postgres:password@db:5432/test
    depends_on:
      - db
      - redis

  db:
    image: postgres:15
    environment:
      POSTGRES_DB: test
      POSTGRES_PASSWORD: password

  redis:
    image: redis:7

在容器中运行测试:

docker-compose -f docker-compose.test.yml up -d
docker-compose -f docker-compose.test.yml exec app npm test
docker-compose -f docker-compose.test.yml down

服务虚拟化

// Mock external services with WireMock
import { WireMock } from 'wiremock-captain';

const wiremock = new WireMock('http://localhost:8080');

// Mock payment gateway
await wiremock.register({
  request: {
    method: 'POST',
    url: '/charge'
  },
  response: {
    status: 200,
    jsonBody: { transactionId: '12345', status: 'approved' }
  }
});

// Tests use mock instead of real gateway

成本优化

# Auto-shutdown test environments after hours
0 20 * * * aws ec2 stop-instances --instance-ids $(aws ec2 describe-instances \
  --filters "Name=tag:Environment,Values=test" \
  --query "Reservations[].Instances[].InstanceId" --output text)

# Start before work hours
0 7 * * 1-5 aws ec2 start-instances --instance-ids $(aws ec2 describe-instances \
  --filters "Name=tag:Environment,Values=test" \
  --query "Reservations[].Instances[].InstanceId" --output text)

使用竞价实例(节省 70%):

resource "aws_instance" "test_runner" {
  instance_type = "c5.2xlarge"
  instance_market_options {
    market_type = "spot"
    spot_options {
      max_price = "0.10"
    }
  }
}

Agent 驱动的环境管理

// Provision test environment
await Task("Environment Provisioning", {
  type: 'integration-testing',
  services: ['app', 'db', 'redis', 'mocks'],
  parity: 'production',
  lifetime: '2h'
}, "qe-test-executor");

// Chaos testing in isolated environment
await Task("Chaos Test Environment", {
  baseline: 'staging',
  isolate: true,
  injectFaults: ['network-delay', 'pod-failure']
}, "qe-chaos-engineer");

Agent 协作提示

记忆命名空间
aqe/environment-management/
├── configs/*            - Environment configurations
├── parity-checks/*      - Dev/prod parity results
├── cost-reports/*       - Infrastructure costs
└── service-mocks/*      - Service virtualization configs
Fleet 协作
const envFleet = await FleetManager.coordinate({
  strategy: 'environment-management',
  agents: [
    'qe-test-executor',       // Provision environments
    'qe-performance-tester',  // Environment performance
    'qe-chaos-engineer'       // Resilience testing
  ],
  topology: 'sequential'
});

相关技能


请记住

使用 Agent: Agent 会自动配置与生产环境相匹配的测试环境,确保环境一致,模拟外部服务,并通过自动扩缩容和自动关闭来优化成本。

评论

支持 Markdown