skills/qc-test-data/SKILL.md
Use when managing test data — designing test data strategies, using factories and builders, creating fixtures, generating synthetic data, masking PII for testing, and managing test database state.
npx skillsauth add kienbui1995/magic-powers qc-test-dataInstall this skill globally with one command. Works with Claude Code, Cursor, and Windsurf.
3 of 9 scanners reported clean
Some scanners were skipped, did not run, or reported a non-clean status. Review each row below.
Strategy 1: Isolated test data (recommended)
Each test creates its own data, deletes it after
✅ Tests are independent, no shared state conflicts
✅ Works with parallel test execution
❌ Slower (DB writes per test)
Strategy 2: Shared base data + test-specific data
Seed base reference data (countries, categories) once
Each test creates entity-specific data
✅ Balance of speed and isolation
✅ Good for data that rarely changes
Strategy 3: Database snapshots
Snapshot DB before test run, restore after
✅ Fast (no per-test cleanup)
❌ Risky for parallel execution
❌ Hard to maintain as schema evolves
Strategy 4: Test containers
Each test run gets fresh ephemeral DB (Docker)
✅ Perfect isolation
✅ Tests database migrations
❌ Slower startup (~5-10s per suite)
# factories.py — centralized test data creation
import factory
from factory.django import DjangoModelFactory
from faker import Faker
fake = Faker()
class UserFactory(DjangoModelFactory):
class Meta:
model = User
email = factory.LazyFunction(lambda: fake.email())
first_name = factory.LazyFunction(lambda: fake.first_name())
last_name = factory.LazyFunction(lambda: fake.last_name())
password = factory.PostGenerationMethodCall('set_password', 'Test1234!')
is_active = True
class OrderFactory(DjangoModelFactory):
class Meta:
model = Order
user = factory.SubFactory(UserFactory) # auto-creates user
status = Order.Status.PENDING
total = factory.LazyFunction(
lambda: fake.pydecimal(min_value=10, max_value=1000, right_digits=2)
)
# Usage in tests
def test_user_can_cancel_order():
order = OrderFactory(status=Order.Status.CONFIRMED)
result = cancel_order(order.id, order.user)
assert result.status == Order.Status.CANCELLED
// TypeScript builder for complex test data
class UserBuilder {
private data = {
email: '[email protected]',
role: 'USER',
isActive: true,
credits: 100,
};
withEmail(email: string) { this.data.email = email; return this; }
withRole(role: string) { this.data.role = role; return this; }
inactive() { this.data.isActive = false; return this; }
withCredits(credits: number) { this.data.credits = credits; return this; }
asAdmin() { this.data.role = 'ADMIN'; return this; }
async build() {
return await createUser(this.data);
}
}
// Usage
const adminUser = await new UserBuilder()
.withEmail('[email protected]')
.asAdmin()
.build();
const lockedUser = await new UserBuilder()
.inactive()
.withCredits(0)
.build();
# pii_masker.py — mask real data for test use
from faker import Faker
fake = Faker()
def mask_user_data(user: dict) -> dict:
"""Replace PII with realistic-looking fake data"""
return {
**user,
'email': fake.email(),
'name': fake.name(),
'phone': fake.phone_number(),
'address': fake.address(),
# Keep non-PII fields for realistic testing
'created_at': user['created_at'],
'plan': user['plan'],
'usage_gb': user['usage_gb'],
}
def mask_production_export(data: list[dict]) -> list[dict]:
"""Safe to use in test environments after masking"""
return [mask_user_data(record) for record in data]
# conftest.py — pytest database management
import pytest
from sqlalchemy import create_engine
from sqlalchemy.orm import Session
@pytest.fixture(scope="session")
def db_engine():
engine = create_engine("postgresql://test:test@localhost/testdb")
run_alembic_migrations(engine)
yield engine
engine.dispose()
@pytest.fixture(autouse=True)
def db_transaction(db_engine):
"""Wrap each test in a transaction that rolls back after"""
connection = db_engine.connect()
transaction = connection.begin()
session = Session(bind=connection)
yield session
session.close()
transaction.rollback() # automatically undone after each test
connection.close()
user_id = 42 (breaks when data changes)setUp but not cleaned up (state leaks between tests)qc-automation — fixtures use these data patternstest-driven-development — TDD tests need isolated data from the startado-pipeline-optimization — parallel test execution requires isolated test datacontent-media
Use when designing for XR (AR/VR/MR), choosing interaction modes, or adapting 2D UI patterns for spatial computing
testing
Use when creating new skills, editing existing skills, or verifying skills work before deployment
development
Use when you have a spec or requirements for a multi-step task, before touching code
development
Use when executing a structured workflow — select and run a feature, bugfix, refactor, research, or incident template with correct agent and model assignments per phase.