Skip to content
cccskills
FreePublished on GitHub

integration-testing

集成测试实现时使用。适用于 API 端到端测试 / 数据库集成 / 第三方 Mock。融合 Testcontainers + Supertest + WireMock。

The English summary is being prepared. Showing the original description.

Works withPostgreSQL
See how to install

Files included (2)

  • SKILL.md3.9 KB
  • templates/integration-test-template.md1.4 KB

SKILL.md (original)

Review the instructions the agent will receive before you install.

集成测试(Integration Testing)

适用场景

  • API 端到端测试(Controller → DB)
  • 数据库集成测试(真实 DB)
  • 第三方服务 Mock(WireMock)
  • 消息队列集成测试
  • 缓存集成测试

核心原则

1. 用真实依赖(Testcontainers)
   不用 H2 / SQLite 替代 PostgreSQL

2. 测试数据隔离
   每个测试独立数据,不共享

3. 覆盖主路径 + 关键失败路径
   不需要覆盖所有边界(单元测试做)

4. 第三方用 Mock(WireMock)
   不依赖真实第三方

Testcontainers

// NestJS + Testcontainers
import { PostgreSqlContainer } from '@testcontainers/postgresql';
import { RedisContainer } from '@testcontainers/redis';

describe('OrderController (Integration)', () => {
  let app: INestApplication;
  let postgres: StartedPostgreSqlContainer;
  
  beforeAll(async () => {
    postgres = await new PostgreSqlContainer('postgres:16').start();
    
    const moduleRef = await Test.createTestingModule({
      imports: [AppModule],
    })
    .overrideProvider('DATABASE_URL')
    .useValue(postgres.getConnectionUri())
    .compile();
    
    app = moduleRef.createNestApplication();
    await app.init();
  });
  
  afterAll(async () => {
    await app.close();
    await postgres.stop();
  });
  
  it('POST /orders creates order', async () => {
    const response = await request(app.getHttpServer())
      .post('/api/v1/orders')
      .set('Authorization', `Bearer ${validToken}`)
      .send({ userId: 1, items: [{ productId: 100, qty: 2 }] })
      .expect(201);
    
    expect(response.body.status).toBe('DRAFT');
  });
  
  it('GET /orders/:id returns 404 for unknown id', async () => {
    await request(app.getHttpServer())
      .get('/api/v1/orders/99999')
      .set('Authorization', `Bearer ${validToken}`)
      .expect(404);
  });
});
# FastAPI + Testcontainers
from testcontainers.postgres import PostgresContainer
import pytest

@pytest.fixture(scope='session')
def postgres():
    with PostgresContainer('postgres:16') as pg:
        yield pg

@pytest.fixture(scope='session')
def client(postgres):
    os.environ['DATABASE_URL'] = postgres.get_connection_url()
    from main import app
    return TestClient(app)

def test_create_order(client, auth_headers):
    response = client.post('/api/v1/orders', json={
        'user_id': 1,
        'items': [{'product_id': 100, 'qty': 2}],
    }, headers=auth_headers)
    assert response.status_code == 201
    assert response.json()['status'] == 'DRAFT'

WireMock(第三方 Mock)

import { WireMockRestClient } from 'wiremock-rest-client';

const wireMock = new WireMockRestClient('http://localhost:8080');

beforeAll(async () => {
  await wireMock.mappings.createMapping({
    request: { method: 'POST', url: '/payment/charge' },
    response: { status: 200, jsonBody: { success: true, transactionId: 'txn_123' } },
  });
});

it('should process payment', async () => {
  const result = await paymentService.charge({ amount: 100, currency: 'USD' });
  expect(result.transactionId).toBe('txn_123');
});

配套模板

  • templates/integration-test-template.md — 集成测试模板

质量自检

□ 用 Testcontainers(真实 DB)
□ 测试数据隔离
□ 第三方用 WireMock
□ 覆盖主路径 + 关键失败
□ 测试独立
□ 清理(afterAll)
□ 不依赖外部网络

常见坑

  1. 用 H2 替代 PG——行为差异
  2. 测试数据不隔离——并行就崩
  3. 依赖真实第三方——CI 不稳定
  4. 不清理容器——资源泄漏
  5. 集成测试太多——慢

与其他 skill 的协作

上游:
  unit-testing → 单元层

下游:
  e2e-testing → E2E 层
  ci-test-integration → CI 集成

Reviews

No reviews yet. Tell others what you thought.

Comments

No login needed. Share how it worked for you, ask a question, or note where it did not run.

No comments yet. Be the first to write one.

Comments are published right away. Do not include personal information such as email addresses or phone numbers. Up to 2 URLs.

0 / 1,000 characters

This form is protected by reCAPTCHA, and the Google Privacy Policy and Terms of Service apply.

More skills from this repository

A/B 测试设计与分析时使用。适用于产品实验、功能验证、转化率优化。融合假设驱动 + 样本量计算 + 置信度判断。

The English summary is being prepared. Showing the original description.

zhaoxuya520/AI-Fullstack-Delivery-Workflow54Updated May 19, 2026

上线前业务方/产品方验收时使用。适用于功能交付确认、UAT、发布会签。融合 BDD Given-When-Then、Specification by Example、ATDD。

The English summary is being prepared. Showing the original description.

zhaoxuya520/AI-Fullstack-Delivery-Workflow54Updated May 19, 2026

设计无障碍可访问的界面时使用。适用于满足 WCAG 标准、键盘导航、屏幕阅读器支持。优先使用 WCAG 2.2 AA 级标准 + 键盘 + 焦点 + 对比度 + ARIA。

The English summary is being prepared. Showing the original description.

zhaoxuya520/AI-Fullstack-Delivery-Workflow54Updated May 19, 2026

实现可访问性(无障碍)时使用。覆盖 WCAG 2.2 AA / ARIA / 键盘导航 / 屏幕阅读器 / 颜色对比 / 焦点管理。融合 React Aria / Radix UI / Headless UI 实践 + axe-core 自动化测试。

The English summary is being prepared. Showing the original description.

zhaoxuya520/AI-Fullstack-Delivery-Workflow54Updated May 19, 2026

AI 模型部署时使用。适用于推理服务 / GPU / TensorRT / 监控 / 扩缩容。

The English summary is being prepared. Showing the original description.

zhaoxuya520/AI-Fullstack-Delivery-Workflow54Updated May 19, 2026

数据分析报告输出时使用。适用于业务分析报告、周报、专项分析、决策支持。融合洞察 + 建议 + 行动项。

The English summary is being prepared. Showing the original description.

zhaoxuya520/AI-Fullstack-Delivery-Workflow54Updated May 19, 2026

See all skills by zhaoxuya520

Report a problem with this skill