AgentSkillsCN

Test Environment Setup

测试环境搭建

SKILL.md

Test Environment Setup

Skill Purpose: Configure and maintain reliable test environments, including databases, services, and environment variables for unit, integration, and E2E testing.


Core Skill Pattern

Objective: Provide repeatable test environment setup that mirrors production-critical behavior without risking production data.

Universal Pattern:

  1. Define environment tiers (local, CI, staging)
  2. Provision dependencies (DB, queues, storage, auth)
  3. Configure environment variables and secrets
  4. Prepare test data and fixtures
  5. Validate readiness with smoke checks

Key Decisions (Project-Specific):

  • Use containers vs shared staging services
  • Test database strategy (ephemeral vs persistent)
  • Secrets management in CI
  • Data reset strategy between runs

Project-Specific Implementation Notes

Customize per project:

  • Use separate test Supabase project or schema
  • Use dedicated test users and API keys
  • Keep .env.test isolated from .env
  • Seed minimal deterministic data for tests

Example Implementation (Next.js + Supabase)

Note: Example only. Adapt to your actual stack and deployment model.

Environment Layout

code
.env.test
.env.ci

Example .env.test

code
NEXT_PUBLIC_SUPABASE_URL=https://test-project.supabase.co
NEXT_PUBLIC_SUPABASE_ANON_KEY=REDACTED
SUPABASE_SERVICE_ROLE_KEY=REDACTED
TEST_DATABASE_URL=postgresql://postgres:postgres@localhost:54322/postgres

Readiness Check (Pseudo)

code
1) Run migrations against TEST_DATABASE_URL
2) Seed base fixtures
3) Verify auth works with test users
4) Run a minimal smoke test suite

Best Practices

  1. Use disposable test data and reset between runs
  2. Keep test envs isolated from production
  3. Store secrets in CI secret manager only
  4. Mirror production config for critical paths
  5. Validate readiness before full test runs

Stop Conditions

STOP and escalate if:

  • Test environment touches production data
  • Required secrets are unavailable
  • Test services are not isolated
  • Data reset strategy is unclear

Skill Version: 1.0.0