configure-integration-tests

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

/configure:integration-tests

/configure:集成测试

Check and configure integration testing infrastructure for testing service interactions, databases, and external dependencies.
检查并配置用于测试服务交互、数据库及外部依赖的集成测试基础设施。

When to Use This Skill

何时使用该技能

Use this skill when...Use another approach when...
Setting up integration testing infrastructure with Supertest, pytest, or TestcontainersWriting individual integration test cases for specific endpoints
Creating docker-compose.test.yml for local test service containersRunning existing integration tests (
bun test
,
pytest -m integration
)
Auditing integration test setup for completeness (fixtures, factories, CI)Configuring unit test runners (
/configure:tests
instead)
Adding integration test jobs to GitHub Actions with service containersDebugging a specific failing integration test
Separating integration tests from unit tests in project structureSetting up API contract testing (
/configure:api-tests
instead)
以下场景使用该技能...以下场景使用其他方案...
使用Supertest、pytest或Testcontainers搭建集成测试基础设施为特定端点编写单个集成测试用例
创建docker-compose.test.yml用于本地测试服务容器运行已有的集成测试(
bun test
pytest -m integration
审核集成测试设置的完整性(fixtures、工厂、CI)配置单元测试运行器(改用
/configure:tests
为GitHub Actions添加包含服务容器的集成测试任务调试特定失败的集成测试
在项目结构中分离集成测试与单元测试配置API契约测试(改用
/configure:api-tests

Context

上下文

  • Project root: !
    pwd
  • Package files: !
    find . -maxdepth 1 \( -name 'package.json' -o -name 'pyproject.toml' -o -name 'Cargo.toml' -o -name 'go.mod' \) 2>/dev/null
  • Integration tests dir: !
    find tests -maxdepth 1 -type d -name 'integration' 2>/dev/null
  • Docker compose test: !
    find . -maxdepth 1 -name 'docker-compose.test.yml' 2>/dev/null
  • Vitest integration config: !
    find . -maxdepth 1 -name 'vitest.integration.config.*' 2>/dev/null
  • Supertest dep: !
    grep -l 'supertest' package.json 2>/dev/null
  • Testcontainers dep: !
    grep -l 'testcontainers' package.json pyproject.toml 2>/dev/null
  • Project standards: !
    find . -maxdepth 1 -name '.project-standards.yaml' 2>/dev/null
  • 项目根目录: !
    pwd
  • 包文件: !
    find . -maxdepth 1 \( -name 'package.json' -o -name 'pyproject.toml' -o -name 'Cargo.toml' -o -name 'go.mod' \) 2>/dev/null
  • 集成测试目录: !
    find tests -maxdepth 1 -type d -name 'integration' 2>/dev/null
  • Docker测试编排文件: !
    find . -maxdepth 1 -name 'docker-compose.test.yml' 2>/dev/null
  • Vitest集成配置: !
    find . -maxdepth 1 -name 'vitest.integration.config.*' 2>/dev/null
  • Supertest依赖: !
    grep -l 'supertest' package.json 2>/dev/null
  • Testcontainers依赖: !
    grep -l 'testcontainers' package.json pyproject.toml 2>/dev/null
  • 项目标准: !
    find . -maxdepth 1 -name '.project-standards.yaml' 2>/dev/null

Parameters

参数

Parse from command arguments:
  • --check-only
    : Report compliance status without modifications (CI/CD mode)
  • --fix
    : Apply fixes automatically without prompting
  • --framework <supertest|pytest|testcontainers>
    : Override framework detection
Integration Testing Stacks:
  • JavaScript/TypeScript: Supertest + Testcontainers
  • Python: pytest + testcontainers-python + httpx
  • Rust: cargo test with
    #[ignore]
    + testcontainers-rs
  • Go: testing + testcontainers-go
Key Difference from Unit Tests:
  • Integration tests interact with real databases, APIs, and services
  • They test component boundaries and data flow
  • They typically require test fixtures and cleanup
从命令参数中解析:
  • --check-only
    : 仅报告合规状态,不进行修改(CI/CD模式)
  • --fix
    : 自动应用修复,无需提示
  • --framework <supertest|pytest|testcontainers>
    : 覆盖框架自动检测
集成测试技术栈:
  • JavaScript/TypeScript: Supertest + Testcontainers
  • Python: pytest + testcontainers-python + httpx
  • Rust: cargo test搭配
    #[ignore]
    + testcontainers-rs
  • Go: testing + testcontainers-go
与单元测试的核心区别:
  • 集成测试与真实数据库、API及服务交互
  • 测试组件边界数据流
  • 通常需要测试fixtures清理操作

Execution

执行流程

Execute this integration testing compliance check:
执行以下集成测试合规性检查:

Step 1: Detect existing integration testing infrastructure

步骤1:检测现有集成测试基础设施

Check for these indicators:
IndicatorComponentStatus
tests/integration/
directory
Integration testsPresent
testcontainers
in dependencies
Container testingConfigured
supertest
in package.json
HTTP testingConfigured
docker-compose.test.yml
Test servicesPresent
pytest.ini
with
integration
marker
pytest integrationConfigured
检查以下指标:
指标组件状态
tests/integration/
目录
集成测试已存在
依赖中包含
testcontainers
容器测试已配置
package.json中包含
supertest
HTTP测试已配置
docker-compose.test.yml
测试服务已存在
带有
integration
标记的
pytest.ini
pytest集成已配置

Step 2: Analyze current state

步骤2:分析当前状态

Check for complete integration testing setup:
Test Organization:
  • tests/integration/
    directory exists
  • Integration tests separated from unit tests
  • Test fixtures and factories present
  • Database seeding/migration scripts
JavaScript/TypeScript (Supertest):
  • supertest
    installed
  • @testcontainers/postgresql
    or similar installed
  • Test database configuration
  • API endpoint tests present
  • Authentication test helpers
Python (pytest + testcontainers):
  • testcontainers
    installed
  • httpx
    or
    requests
    for HTTP testing
  • pytest-asyncio
    for async tests
  • integration
    marker defined
  • Database fixtures in
    conftest.py
Container Infrastructure:
  • docker-compose.test.yml
    exists
  • Test database container defined
  • Redis/cache container (if needed)
  • Network isolation configured
检查集成测试设置是否完整:
测试组织:
  • 存在
    tests/integration/
    目录
  • 集成测试与单元测试分离
  • 存在测试fixtures和工厂
  • 存在数据库填充/迁移脚本
JavaScript/TypeScript(Supertest):
  • 已安装
    supertest
  • 已安装
    @testcontainers/postgresql
    或类似包
  • 测试数据库已配置
  • 存在API端点测试
  • 存在认证测试辅助工具
Python(pytest + testcontainers):
  • 已安装
    testcontainers
  • 已安装
    httpx
    requests
    用于HTTP测试
  • 已安装
    pytest-asyncio
    用于异步测试
  • 已定义
    integration
    标记
  • conftest.py
    中存在数据库fixtures
容器基础设施:
  • 存在
    docker-compose.test.yml
  • 已定义测试数据库容器
  • 已定义Redis/缓存容器(如需要)
  • 已配置网络隔离

Step 3: Generate compliance report

步骤3:生成合规性报告

Print a formatted compliance report:
Integration Testing Compliance Report
======================================
Project: [name]
Language: [TypeScript | Python | Rust | Go]

Test Organization:
  Integration directory    tests/integration/         [EXISTS | MISSING]
  Separated from unit      not in src/                [CORRECT | MIXED]
  Test fixtures            tests/fixtures/            [EXISTS | MISSING]
  Database seeds           tests/seeds/               [EXISTS | N/A]

Framework Setup:
  HTTP testing             supertest/httpx            [INSTALLED | MISSING]
  Container testing        testcontainers             [INSTALLED | MISSING]
  Async support            pytest-asyncio             [INSTALLED | N/A]

Infrastructure:
  docker-compose.test.yml  test services              [EXISTS | MISSING]
  Test database            PostgreSQL/SQLite          [CONFIGURED | MISSING]
  Service isolation        network config             [CONFIGURED | MISSING]

CI/CD Integration:
  Integration test job     GitHub Actions             [CONFIGURED | MISSING]
  Service containers       workflow services          [CONFIGURED | MISSING]

Overall: [X issues found]

Recommendations:
  - Install testcontainers for database testing
  - Create docker-compose.test.yml for local testing
  - Add integration test job to CI workflow
If
--check-only
, stop here.
打印格式化的合规性报告:
集成测试合规性报告
======================================
项目: [名称]
语言: [TypeScript | Python | Rust | Go]

测试组织:
  集成测试目录    tests/integration/         [已存在 | 缺失]
  与单元测试分离      不在src/目录中                [正确 | 混合]
  测试fixtures            tests/fixtures/            [已存在 | 缺失]
  数据库填充脚本           tests/seeds/               [已存在 | 不适用]

框架设置:
  HTTP测试             supertest/httpx            [已安装 | 缺失]
  容器测试        testcontainers             [已安装 | 缺失]
  异步支持            pytest-asyncio             [已安装 | 不适用]

基础设施:
  docker-compose.test.yml  测试服务              [已存在 | 缺失]
  测试数据库            PostgreSQL/SQLite          [已配置 | 缺失]
  服务隔离        网络配置             [已配置 | 缺失]

CI/CD集成:
  集成测试任务     GitHub Actions             [已配置 | 缺失]
  服务容器       工作流服务          [已配置 | 缺失]

整体状态: [发现X个问题]

建议:
  - 安装testcontainers用于数据库测试
  - 创建docker-compose.test.yml用于本地测试
  - 为CI工作流添加集成测试任务
如果使用
--check-only
参数,流程到此结束。

Step 4: Configure integration testing (if --fix or user confirms)

步骤4:配置集成测试(如果使用--fix或用户确认)

Apply configuration based on detected project type. Use templates from REFERENCE.md:
  1. Install dependencies (supertest, testcontainers, etc.)
  2. Create test directory (
    tests/integration/
    ) with setup files
  3. Create sample tests for API endpoints and database operations
  4. Create Vitest integration config (JS/TS) or pytest markers (Python)
  5. Add scripts to package.json or create run commands
根据检测到的项目类型应用配置,使用REFERENCE.md中的模板:
  1. 安装依赖(supertest、testcontainers等)
  2. 创建测试目录
    tests/integration/
    )及设置文件
  3. 创建示例测试,覆盖API端点和数据库操作
  4. 创建Vitest集成配置(JS/TS)或pytest标记(Python)
  5. 添加脚本到package.json或创建运行命令

Step 5: Create container infrastructure

步骤5:创建容器基础设施

Create
docker-compose.test.yml
with:
  • PostgreSQL test database (tmpfs for speed)
  • Redis test instance (if needed)
  • Network isolation
Add corresponding npm/bun scripts for managing test containers. Use templates from REFERENCE.md.
创建
docker-compose.test.yml
,包含:
  • PostgreSQL测试数据库(使用tmpfs提升速度)
  • Redis测试实例(如需要)
  • 网络隔离
添加对应的npm/bun脚本用于管理测试容器,使用REFERENCE.md中的模板。

Step 6: Configure CI/CD integration

步骤6:配置CI/CD集成

Add integration test job to
.github/workflows/test.yml
with:
  • Service containers (postgres, redis)
  • Database migration step
  • Integration test execution
  • Artifact upload for test results
Use the CI workflow template from REFERENCE.md.
.github/workflows/test.yml
添加集成测试任务,包含:
  • 服务容器(postgres、redis)
  • 数据库迁移步骤
  • 集成测试执行
  • 测试结果工件上传
使用REFERENCE.md中的CI工作流模板。

Step 7: Create test fixtures and factories

步骤7:创建测试fixtures和工厂

Create
tests/fixtures/factories.ts
(or Python equivalent) with:
  • Data factory functions using faker
  • Database seeding helpers
  • Cleanup utilities
Use factory templates from REFERENCE.md.
创建
tests/fixtures/factories.ts
(或Python等效文件),包含:
  • 使用faker的数据工厂函数
  • 数据库填充辅助工具
  • 清理工具
使用REFERENCE.md中的工厂模板。

Step 8: Update standards tracking

步骤8:更新标准跟踪

Update
.project-standards.yaml
:
yaml
standards_version: "2025.1"
last_configured: "[timestamp]"
components:
  integration_tests: "2025.1"
  integration_tests_framework: "[supertest|pytest|testcontainers]"
  integration_tests_containers: true
  integration_tests_ci: true
更新
.project-standards.yaml
yaml
standards_version: "2025.1"
last_configured: "[时间戳]"
components:
  integration_tests: "2025.1"
  integration_tests_framework: "[supertest|pytest|testcontainers]"
  integration_tests_containers: true
  integration_tests_ci: true

Step 9: Print final report

步骤9:打印最终报告

Print a summary of changes applied, scripts added, and next steps for running integration tests.
For detailed templates and code examples, see REFERENCE.md.
打印已应用的变更、添加的脚本以及运行集成测试的后续步骤。
如需详细模板和代码示例,请查看REFERENCE.md

Agentic Optimizations

Agent优化命令

ContextCommand
Quick compliance check
/configure:integration-tests --check-only
Auto-fix all issues
/configure:integration-tests --fix
Run integration tests (JS)
bun test tests/integration --dots --bail=1
Run integration tests (Python)
pytest -m integration -x -q
Start test containers
docker compose -f docker-compose.test.yml up -d
Check container health`docker compose -f docker-compose.test.yml ps --format json
上下文命令
快速合规性检查
/configure:integration-tests --check-only
自动修复所有问题
/configure:integration-tests --fix
运行集成测试(JS)
bun test tests/integration --dots --bail=1
运行集成测试(Python)
pytest -m integration -x -q
启动测试容器
docker compose -f docker-compose.test.yml up -d
检查容器健康状态`docker compose -f docker-compose.test.yml ps --format json

Flags

标志

FlagDescription
--check-only
Report status without offering fixes
--fix
Apply all fixes automatically without prompting
--framework <framework>
Override framework detection (supertest, pytest, testcontainers)
标志描述
--check-only
仅报告状态,不提供修复选项
--fix
自动应用所有修复,无需提示
--framework <framework>
覆盖框架自动检测(supertest、pytest、testcontainers)

Examples

示例

bash
undefined
bash
undefined

Check compliance and offer fixes

检查合规性并提供修复选项

/configure:integration-tests
/configure:integration-tests

Check only, no modifications

仅检查,不修改

/configure:integration-tests --check-only
/configure:integration-tests --check-only

Auto-fix all issues

自动修复所有问题

/configure:integration-tests --fix
/configure:integration-tests --fix

Force specific framework

强制使用特定框架

/configure:integration-tests --fix --framework pytest
undefined
/configure:integration-tests --fix --framework pytest
undefined

Error Handling

错误处理

  • No app entry point found: Ask user to specify app location
  • Docker not available: Warn about testcontainers requirement
  • Database type unknown: Ask user to specify database type
  • Port conflicts: Suggest alternative ports in docker-compose
  • 未找到应用入口: 询问用户指定应用位置
  • Docker不可用: 警告Testcontainers的依赖要求
  • 数据库类型未知: 询问用户指定数据库类型
  • 端口冲突: 建议在docker-compose中使用替代端口

See Also

相关链接