test-environment-management

实现测试环境的全生命周期管理,包括按需创建符合生产环境规格的容器化或云上基础设施,自动校验开发与生产环境的一致性,虚拟化外部依赖服务,并通过自动启停、竞价实例等策略优化资源成本。

快捷安装

在终端运行此命令,即可一键安装该 Skill 到您的 Claude 中

npx skills add proffesor-for-testing/agentic-qe --skill "test-environment-management"

Test Environment Management

<default_to_action> When managing test environments:

  1. DEFINE environment types (local, CI, staging, prod)
  2. CONTAINERIZE with Docker for consistency
  3. ENSURE parity with production (same versions, configs)
  4. MOCK external services (service virtualization)
  5. OPTIMIZE costs (auto-shutdown, spot instances)

Quick Environment Checklist:

  • Same OS/versions as production
  • Same database type and version
  • Same configuration structure
  • Containers for reproducibility
  • Auto-shutdown after hours

Critical Success Factors:

  • “Works on my machine” = environment inconsistency
  • Infrastructure as Code = repeatable environments
  • Service virtualization = test without external dependencies </default_to_action>

Quick Reference Card

When to Use

  • Setting up test infrastructure
  • Debugging environment-specific failures
  • Reducing test infrastructure costs
  • Ensuring dev/prod parity

Docker for Test Environments

# 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

Run tests in container:

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

Service Virtualization

// 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

Cost Optimization

# 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)

Use spot instances (70% savings):

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

Agent-Driven Environment Management

// 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 Coordination Hints

Memory Namespace

aqe/environment-management/
├── configs/*            - Environment configurations
├── parity-checks/*      - Dev/prod parity results
├── cost-reports/*       - Infrastructure costs
└── service-mocks/*      - Service virtualization configs

Fleet Coordination

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'
});


Remember

With Agents: Agents automatically provision test environments matching production, ensure parity, mock external services, and optimize costs with auto-scaling and auto-shutdown.