--- id: wiki-2026-0508-test-automation title: Test Automation category: 10_Wiki/Topics status: verified canonical_id: self aliases: [automated testing, test automation pyramid, CI testing] duplicate_of: none source_trust_level: A confidence_score: 0.95 verification_status: applied tags: [testing, automation, ci-cd, qa, devops] raw_sources: [] last_reinforced: 2026-05-10 github_commit: pending tech_stack: language: typescript framework: 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 ```typescript 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 ```typescript 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) ```typescript 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) ```typescript 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) ```typescript 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) ```typescript 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) ```typescript test.describe.configure({ retries: 2 }); test('flaky-known @quarantine', async ({ page }) => { /* ... */ }); // CI: skip @quarantine on PR, run nightly only ``` ### k6 load test ```javascript 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 - 부모: [[Software Quality]] - 변형: [[TDD]] · [[BDD]] · [[Property-based Testing]] - 응용: [[Continuous Integration]] · [[Visual Regression]] - Adjacent: [[Playwright]] · [[Pact]] ## 🤖 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 |