Salesforce Dictionary - Free Salesforce GlossarySalesforce Dictionary
Salesforce QA / Tester
medium

How do you manage test data for Salesforce testing?

Test data is the input that exercises tests. Strategy matters.

Approaches:

1. Apex test data factories.

apex public class TestDataFactory { public static List<Account> createAccounts(Integer n) { List<Account> accs = new List<Account>(); for (Integer i = 0; i < n; i++) { accs.add(new Account(Name='Test Account '+i)); } insert accs; return accs; } }

Used by all Apex tests. Centralised; reusable.

2. `@TestSetup`.

Class-level setup that runs once per test class. Shared data; rolled back at end.

3. Manual sandbox data for UAT.

  • Real-looking data for business user testing.
  • Curated; representative of production.
  • Refreshed periodically.

4. Anonymised production data.

  • Sensitive fields masked.
  • Realistic distributions, scale.
  • For performance testing, UAT.

Tools: OwnBackup Sandbox Seeding, Gearset Compare, custom scripts.

5. Synthetic data generation.

  • Tools generate volume data.
  • Faker library for realistic-looking values.
  • For performance / load testing.

6. CSV / JSON files.

  • For data-driven tests (Provar, custom).
  • Same data across test runs.

Architecture:

  • Factory class for unit tests.
  • Anonymised data set for UAT.
  • Synthetic data for performance.

Common pitfalls:

  • `SeeAllData=true` tests — depend on org data; fragile.
  • Inline data setup — duplicated across tests.
  • Production data in sandboxes unmasked — compliance risk.
  • Stale UAT data — doesn't represent current production.

Senior QA insight: test data is QA infrastructure. Invest in factories, anonymisation tools, synthetic data generation.

The senior framing: bad test data = bad tests. Garbage in, garbage out.

Why this answer works

Senior. The approach catalog and factory-pattern emphasis are mature.

Follow-ups to expect

Related dictionary terms