nerdexam
Salesforce

PDI · Question #100

A developer needs to create a baseline set of data (Account, Contacts, Products, Assets) for an entire suite allowing them to test independent requirements for various types of Salesforce Cases…

The correct answer is A. Use &TestSteup with a void method. The question asks for the most efficient way to generate a common baseline set of data for multiple Apex unit tests.

Submitted by valeria.br· Apr 18, 2026Testing, Debugging, and Deployment

Question

A developer needs to create a baseline set of data (Account, Contacts, Products, Assets) for an entire suite allowing them to test independent requirements for various types of Salesforce Cases. Which approach can efficiently generate the required data for each unit test?

Options

  • AUse &TestSteup with a void method.
  • BCreate test data before Test.startTest in the unit test.
  • CCreate a mock using the Stub APL.
  • DAdd $ IsTest (seeAllDatatrue) at the start of the unit test class.

How the community answered

(15 responses)
  • A
    80% (12)
  • B
    7% (1)
  • C
    13% (2)

Why each option

The question asks for the most efficient way to generate a common baseline set of data for multiple Apex unit tests.

AUse &TestSteup with a void method.Correct

Using the `@TestSetup` annotation with a `void` method allows common test records to be created once for an entire test class, making them available to all test methods and significantly improving test execution efficiency by avoiding repetitive data creation.

BCreate test data before Test.startTest in the unit test.

Creating test data within each individual unit test method is less efficient as it duplicates data creation efforts and increases overall test execution time.

CCreate a mock using the Stub APL.

Creating a mock using the Stub API is for isolating external dependencies and simulating responses, not for efficiently generating actual baseline records for DML operations within unit tests.

DAdd $ IsTest (seeAllDatatrue) at the start of the unit test class.

Using `@IsTest(seeAllData=true)` allows access to existing organization data, which is discouraged for unit testing best practices due to potential test inconsistency and fragility, and it does not generate new test data.

Concept tested: Efficient Apex test data setup

Source: https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_testing_unittest_method.htm#apex_testing_unittest_method_testsetup

Topics

#Apex Testing#Test Data#@TestSetup#Unit Tests

Community Discussion

No community discussion yet for this question.

Full PDI Practice