Test Data Mgmt
Challenges
- Real prod data có PII → privacy violation.
- Synthetic data lack edge case real data has.
- Test depend on specific data state.
- Data refresh blow up parallel test.
Strategies
1. Test data factory
const userFactory = {
build: (overrides = {}) => ({
name: 'Khang ' + Date.now(),
email: khang${Date.now()}@test.vn,
role: 'admin',
...overrides
})
};
const u = userFactory.build({ role: 'guest' });
2. Database fixtures
- Seed file run before suite.
- Use transaction rollback to reset.
3. API setup endpoints
POST /test/users — create test user.
DELETE /test/users/:id — cleanup.
- Only enabled in non-prod env.
4. Snapshot / refresh
- Weekly anonymize prod → staging.
- Tools: Delphix, Tonic, Mockaroo.
VN compliance
Luật ATTT, Personal Data Protection Decree 2023:
- Mask name, phone, ID number.
- Salt hash password.
- Strip address detail (keep city only).
Anonymization techniques
- Pseudo — replace name with "User1, User2".
- Generalization — exact age → age range.
- Perturbation — small random offset to salary.
- Synthesis — generate fresh fake data.
Anti-pattern
- Share staging account in Slack → security risk.
- Hardcode test account ID in test code → fragile.
- Cleanup miss → DB grow infinite over months.
Idempotency
Test should leave env in same state as start. Even when fail (use try/finally cleanup).