Files
2nd/10_Wiki/Topics/DevOps_and_Security/Test_Automation.md
T
Antigravity Agent f8b21af4be Wiki cleanup: error-doc removal, dedup merge, link normalization
10_Wiki/Topics 대규모 정리:
- 오류 캡처/미완성 stub 문서 227개 제거
- 교차폴더 중복 43클러스터 병합 (63파일 → redirect)
- 링크명 정규화: 깨진 링크 수정·redirect 직결·개념 매핑 ~2,400건
- 카테고리 MOC 6개 신규 생성
- Graph 섹션 미해결 related-keyword 링크 10,058건 제거

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-20 23:52:15 +09:00

6.3 KiB

id, title, category, status, canonical_id, aliases, duplicate_of, source_trust_level, confidence_score, verification_status, tags, raw_sources, last_reinforced, github_commit, tech_stack
id title category status canonical_id aliases duplicate_of source_trust_level confidence_score verification_status tags raw_sources last_reinforced github_commit tech_stack
wiki-2026-0508-test-automation Test Automation 10_Wiki/Topics verified self
automated testing
test automation pyramid
CI testing
none A 0.95 applied
testing
automation
ci-cd
qa
devops
2026-05-10 pending
language framework
typescript vitest-playwright-msw-pact

Test Automation

매 한 줄

"매 confidence 의 deploy 의 — 매 tests 의 paying 의". Test automation 의 unit / integration / e2e / contract / performance 의 의 CI 의 의 mechanically running 의 의 — 매 regression 의 catch, 매 deploy velocity 의 unlock. 2026 의 stack: Vitest (unit), Playwright (e2e), MSW (API mock), Pact (contract), k6 (load).

매 핵심

매 testing pyramid (modern)

  • Unit (60-70%): 매 fast (<100ms each), 매 isolated, 매 logic 의.
  • Integration (20-30%): 매 real DB / Redis 의 (testcontainers), 매 module boundaries.
  • Component (10%): 매 React/Vue 의 isolated rendering.
  • E2E (5-10%): 매 Playwright, 매 critical user journeys 의 only.
  • Contract: producer/consumer 의 — 매 microservices.

매 매 modern paradigms

  • TDD still relevant for libraries / domain logic.
  • Snapshot testing judiciously — 매 churn explosion 위험.
  • Property-based (fast-check, hypothesis) — 매 invariants.
  • Visual regression (Chromatic, Percy, Playwright trace).

매 응용

  1. PR-blocking unit + critical e2e.
  2. Pre-merge contract tests (Pact broker).
  3. Nightly load test + regression budget.

💻 패턴

Vitest unit test

import { describe, it, expect, vi } from 'vitest';
import { calcTax } from './tax';

describe('calcTax', () => {
  it.each([
    [100, 'CA', 8.25],
    [100, 'OR', 0],
  ])('%i in %s = %f', (amt, state, expected) => {
    expect(calcTax(amt, state)).toBe(expected);
  });
  it('rejects negative', () => {
    expect(() => calcTax(-1, 'CA')).toThrow(/non-negative/);
  });
});

MSW — API mocking

import { http, HttpResponse } from 'msw';
import { setupServer } from 'msw/node';

export const server = setupServer(
  http.get('/api/users/:id', ({ params }) =>
    HttpResponse.json({ id: params.id, name: 'Alice' })),
);
beforeAll(() => server.listen({ onUnhandledRequest: 'error' }));
afterEach(() => server.resetHandlers());
afterAll(() => server.close());

Playwright e2e (critical path)

import { test, expect } from '@playwright/test';

test('checkout flow', async ({ page }) => {
  await page.goto('/');
  await page.getByRole('button', { name: /add to cart/i }).first().click();
  await page.getByRole('link', { name: /cart/i }).click();
  await page.getByRole('button', { name: /checkout/i }).click();
  await page.getByLabel(/email/i).fill('test@example.com');
  await page.getByLabel(/card number/i).fill('4242424242424242');
  await page.getByRole('button', { name: /pay/i }).click();
  await expect(page.getByRole('heading', { name: /thank you/i })).toBeVisible();
});

Testcontainers (real Postgres in CI)

import { PostgreSqlContainer } from '@testcontainers/postgresql';
let container: any, db: any;
beforeAll(async () => {
  container = await new PostgreSqlContainer('postgres:16').start();
  db = drizzle(postgres(container.getConnectionUri()));
  await migrate(db, { migrationsFolder: './drizzle' });
}, 60_000);
afterAll(async () => container.stop());

Pact contract test (consumer)

import { PactV3, MatchersV3 } from '@pact-foundation/pact';
const provider = new PactV3({ consumer: 'web', provider: 'api' });
provider.given('user 1 exists').uponReceiving('a request for user 1')
  .withRequest({ method: 'GET', path: '/users/1' })
  .willRespondWith({ status: 200, body: MatchersV3.like({ id: 1, name: 'Alice' }) });
await provider.executeTest(async (mock) => {
  const r = await fetch(`${mock.url}/users/1`);
  expect((await r.json()).name).toBe('Alice');
});

Property-based (fast-check)

import fc from 'fast-check';
test('reverse twice = identity', () => {
  fc.assert(fc.property(fc.array(fc.integer()), (arr) => {
    expect([...arr].reverse().reverse()).toEqual(arr);
  }));
});

Flaky-test quarantine (Playwright)

test.describe.configure({ retries: 2 });
test('flaky-known @quarantine', async ({ page }) => { /* ... */ });
// CI: skip @quarantine on PR, run nightly only

k6 load test

import http from 'k6/http';
import { check } from 'k6';
export const options = {
  stages: [{ duration: '2m', target: 100 }, { duration: '5m', target: 100 }],
  thresholds: { http_req_duration: ['p(99)<500'] },
};
export default () => {
  const r = http.get('https://staging.app/api/items');
  check(r, { '200': (x) => x.status === 200 });
};

매 결정 기준

상황 Layer
pure function / domain logic unit (Vitest)
DB query / SQL correctness integration (testcontainers)
critical revenue path e2e (Playwright)
microservice API stability contract (Pact)
invariant property property-based (fast-check)

기본값: 60/30/10 unit/integration/e2e split, MSW for external APIs, testcontainers for DB, Pact for service boundaries.

🔗 Graph

🤖 LLM 활용

언제: test scaffolding from impl, edge-case enumeration, flaky root-cause analysis from trace.zip, snapshot diff explanation. 언제 X: auto-generated tests 의 review 없이 의 merge — 매 tautological tests (mock returns x → assert x).

안티패턴

  • Ice-cream cone (e2e-heavy, unit-light): 매 slow CI, 매 flaky.
  • Mocking what you don't own (deep mocks of fetch): 매 mock drift.
  • Snapshot of everything: 매 PR diff 의 noise.
  • Shared mutable state in tests: 매 order-dependent flaky.
  • No quarantine: 매 1 flaky 의 CI 의 distrust.

🧪 검증 / 중복

  • Verified (Vitest docs, Playwright docs, MSW v2, Pact docs, k6 docs, Kent Beck TDD).
  • 신뢰도 A.

🕓 Changelog

날짜 변경
2026-05-08 Phase 1
2026-05-10 Manual cleanup — pyramid + Vitest/Playwright/MSW/Pact patterns