test-data-management-strategy
Test data strategy — synthetic (factories / faker / constraints) vs masked (redact / tokenize / pseudonymize) vs subset vs frozen. GDPR rails. Lifecycle (generate / seed / reset / refresh). Determinism. Fixtures + goldens. Not legal advice.
What this skill does
# Test Data Management Strategy You design where test data comes from, how it's protected, how it flows between environments, and how it stays reproducible. Getting this wrong is the top reason lower environments leak PII. ## Core rules - **Never raw prod PII in lower envs** — synthetic or masked, always - **Determinism by default** — reproducible seeds + controlled randomness - **Smallest useful dataset** — don't drag prod-sized data around "just in case" - **Reset is explicit** — tests don't rely on previous state - **Masking ≠ deletion** — re-identification risk exists; evaluate it - **Production is the authority** for schemas + distributions, not the source of bytes - **Not legal advice** — GDPR / HIPAA / PCI obligations require counsel + DPO - **No fabricated compliance claims** ## Input handling | Dimension | Required | Default | |---|---|---| | **Environments** (dev / CI / integration / staging / perf / UAT) | Yes | — | | **Data classes** (PII, health, financial, proprietary, non-sensitive) | Yes | — | | **Compliance** (GDPR / HIPAA / PCI) | Yes | — | | **Test levels in scope** | No | Asked | | **Scale needs** (100 rows / 10M) | No | Asked | | **Existing data tooling** | No | Asked | ## Phase 1 — Setup ``` **Environments**: [list] **Data classes**: [PII + financial + health + proprietary + non-sensitive] **Compliance**: [GDPR / HIPAA / PCI / sector] **Test levels**: [unit / component / integration / E2E / perf / UAT] **Scale**: [baseline + perf sizing] **Existing tooling**: [factories / seeds / snapshots / masking tools] **Current pain**: [flaky due to data / prod data leaking / slow seeds] ``` > **Disclaimer**: Not legal advice. Compliance decisions require counsel and DPO. Ask render mode per `diagram-rendering` mixin and output path (default: `/documentation/[case]/test-data-management-strategy/`). ## Phase 2 — Data source strategies ### A. Synthetic (preferred default for lower envs) - Generated via factories / builders / faker libraries with domain constraints - No PII risk; deterministic - Suited for: unit, component, integration, most E2E - Scales cheaply; reproducible via seeds ### B. Masked / pseudonymized - Redact + tokenize sensitive fields; keep schema + distribution - Suited for: realistic data distributions (analytics, search relevance, large-joins) - Risk: re-identification via quasi-identifiers (ZIP + DOB + gender) - Use k-anonymity / l-diversity where possible - Requires DPA + policy sign-off ### C. Subset from production (curated slice) - Cherry-picked + masked subset to limit volume - Suited for: upgrade testing, perf at approximated scale - Risk: accidental selection of sensitive edge cases; subset drift over time ### D. Frozen golden datasets - Versioned + immutable; source-of-truth for regression assertions - Suited for: ML eval sets, compiler tests, algorithm tests, billing invariants - Risk: staleness; coupling between tests + data ### E. Live / sandbox third-party data - Vendor sandbox (e.g., Stripe test keys) with fake cards - Suited for: external-integration tests - Risk: sandbox outages + rate limits + behavioral drift Choose per environment × test level — not one-size-fits-all. ## Phase 3 — Per-environment data matrix | Env | Primary source | Secondary | Notes | |---|---|---|---| | Local / dev | synthetic factories | seeded snapshots | fast; offline-capable | | CI (PR) | synthetic factories | per-test seeding | ephemeral per-run | | Integration | synthetic + seeded fixtures | golden datasets | shared; reset nightly | | Staging | subset masked | synthetic for new tests | closest to prod distribution | | Performance | generated-at-scale synthetic | optional masked subset | deterministic seed | | UAT | curated synthetic personas | + golden | stable cohorts for demos | Prod data never copied raw to any env. ## Phase 4 — Masking techniques | Technique | What it does | Retains | |---|---|---| | **Redaction** | blank sensitive fields | nothing | | **Tokenization** | replace value with token; vault stores mapping | referential integrity | | **Pseudonymization** | deterministic hash / replacement | joinability | | **Generalization** | reduce precision (age 37 → 30-39) | distribution | | **Noise injection** | add bounded noise to numerics | statistical properties | | **Synthesis** | generate new data matching aggregate stats | distribution, no direct mapping | Select per field per need: | Field | Class | Technique | |---|---|---| | email | PII direct | pseudonymize → `user_<hash>@example.test` | | phone | PII direct | pseudonymize with format preservation | | DOB | quasi-identifier | generalize to decade | | ZIP | quasi-identifier | truncate to first 3 | | SSN / national id | regulated | tokenize via vault | | card number | PCI | never leaves prod; use test numbers | | health diagnosis | sensitive | generalize category | ## Phase 5 — Re-identification risk Quasi-identifiers combined can re-identify: - Age + ZIP + gender uniquely identifies a large % of US residents - Timestamp + location → likely identity - Long chains of actions → behavior fingerprint Mitigations: - k-anonymity (≥ k identical records on quasi-identifiers) - l-diversity (≥ l distinct sensitive values per equivalence class) - Differential privacy for aggregate shares - Avoid joining masked data with other sources in lower envs Evaluate risk per dataset. Document in a DPIA attachment when required. ## Phase 6 — Lifecycle ### Generation - Factories produce valid domain aggregates: `OrderFactory.build()` with sensible defaults - Composable overrides: `OrderFactory.build(status: 'refunded')` - Libraries: factory_bot (Ruby) / factory-boy (Python) / fishery (JS) / Bogus (.NET) / Faker in all ### Seeding - Deterministic seeds per test - Idempotent seed scripts (re-runnable) - Transactional where possible (rollback post-test) - Testcontainers: spin a fresh DB per suite run or per worker ### Reset - Truncate + reseed between tests to avoid cross-contamination - Snapshot/restore patterns (e.g., pg-restore, `BEGIN; ... ROLLBACK;`) - Avoid sleep-based waits — use event / polling ### Refresh - Staging refresh cadence (weekly, monthly) - Refresh pipeline: extract subset → mask → load → smoke test - Promote only after masking validated ## Phase 7 — Scale needs (perf testing) - Generate sized data deterministically with known distributions - Seed = config + commit-sha for reproducibility - Use parallel generators for speed - Store in a performance-env database separate from staging - Warm caches before measurement Hand off perf scenarios to `non-functional-test-planning`. ## Phase 8 — Reference / master data Some data isn't test-specific — reference tables (currencies, countries, SKU catalog). Policy: - Source of truth: repo + migration seeds - Versioned with the app - Kept minimal in lower envs unless needed for integration ## Phase 9 — Third-party sandboxes - Document vendor-sandbox requirements per integration - Rotate credentials; never use prod vendor keys in lower envs - Record fixtures from sandbox where flakiness or rate limits hurt - Decision: live sandbox vs recorded fixtures per test reliability needs ## Phase 10 — Data tooling | Need | Tools | |---|---| | Factories | factory_bot / factory-boy / fishery / Bogus | | Masking | Delphix / IBM Optim / tonic.ai / custom ETL | | Synthesis (AI) | Gretel.ai / MOSTLY AI (evaluate re-id risk) | | Snapshot / restore | pg-restore / mysqldump + dataset / LiteFS | | Seeding scripts | SQL / migrations / code-based factories | | Deterministic fake | faker with seed | | Vault for tokens | HashiCorp Vault / cloud secrets | ## Phase 11 — Governance - Owner of test-data strategy (QA lead / data engineer) - Review cadence (quarterly) - Incident: if prod data detected in lower env → remove + investigate + DPO - Audit trail for refresh pipelines ## Phase 12 — Anti-patterns | Anti-pattern | Fix | |---|---| | Raw prod dump in dev | Forbidden; replace with synthetic / masked | | Sha
Related in Code Review
gstack
IncludedFast headless browser for QA testing and site dogfooding. Navigate pages, interact with elements, verify state, diff before/after, take annotated screenshots, test responsive layouts, forms, uploads, dialogs, and capture bug evidence. Use when asked to open or test a site, verify a deployment, dogfood a user flow, or file a bug with screenshots. (gstack)
startup-due-diligence
IncludedLegal due diligence review for seed-stage and Series A startups (US, Delaware C-Corp focus). Supports both investor and founder perspectives. Capabilities include: (1) Interactive document review and issue spotting; (2) Document request list generation; (3) Cap table and SAFE/convertible note analysis; (4) Red flag identification with severity ratings; (5) Diligence report generation. TRIGGERS: due diligence, DD, startup investment, cap table review, Series A, seed round, investor diligence, legal review startup, SAFE analysis, convertible note, 409A, founder vesting.
interview-master
IncludedThis skill should be used when the user asks to "generate interview questions", "prepare for interview", "optimize resume", "conduct mock interview", "analyze git commits for resume", "generate resume from code", "review my resume", or mentions interview preparation, career assistance, or extracting project experience from git history. Provides comprehensive interview and career development guidance for both job seekers and interviewers.
fix-issue
IncludedFixes GitHub issues using parallel analysis agents for root cause investigation, code exploration, and regression detection. Reads issue context from gh CLI, searches codebase and memory for related patterns, generates a fix with tests, and links the resolution back to the issue via PR. Includes prevention analysis to avoid recurrence. Use when debugging errors, resolving regressions, fixing bugs, or triaging issues.
sf-apex
IncludedGenerates and reviews Salesforce Apex code with 150-point scoring. TRIGGER when: user writes, reviews, or fixes Apex classes, triggers, test classes, batch/queueable/schedulable jobs, or touches .cls/.trigger files. DO NOT TRIGGER when: LWC JavaScript (use sf-lwc), Flow XML (use sf-flow), SOQL-only queries (use sf-soql), or non-Salesforce code.
swift-development
IncludedComprehensive Swift development for building, testing, and deploying iOS/macOS applications. Use when Claude needs to: (1) Build Swift packages or Xcode projects from command line, (2) Run tests with XCTest or Swift Testing framework, (3) Manage iOS simulators with simctl, (4) Handle code signing, provisioning profiles, and app distribution, (5) Format or lint Swift code with SwiftFormat/SwiftLint, (6) Work with Swift Package Manager (SPM), (7) Implement Swift 6 concurrency patterns (async/await, actors, Sendable), (8) Create SwiftUI views with MVVM architecture, (9) Set up Core Data or SwiftData persistence, or any other Swift/iOS/macOS development tasks.