From magic-powers
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 claudepluginhub kienbui1995/magic-powers --plugin magic-powersThis skill uses the workspace's default tool permissions.
- Tests break because they depend on specific production data
Generates design tokens/docs from CSS/Tailwind/styled-components codebases, audits visual consistency across 10 dimensions, detects AI slop in UI.
Records polished WebM UI demo videos of web apps using Playwright with cursor overlay, natural pacing, and three-phase scripting. Activates for demo, walkthrough, screen recording, or tutorial requests.
Delivers idiomatic Kotlin patterns for null safety, immutability, sealed classes, coroutines, Flows, extensions, DSL builders, and Gradle DSL. Use when writing, reviewing, refactoring, or designing Kotlin code.
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: 'test@example.com',
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('admin@test.com')
.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 data