nerdexam
Salesforce

PDI · Question #107

A developer is writing tests for a class and needs to insert records to validate functionality. Which annotation method should be used to create record for every method in the test class?

The correct answer is C. @TestSetup. The @TestSetup annotation method should be used to create common test records once for all test methods within a test class, optimizing test execution and setup time.

Submitted by anjalisingh· Apr 18, 2026Testing, Debugging, and Deployment

Question

A developer is writing tests for a class and needs to insert records to validate functionality. Which annotation method should be used to create record for every method in the test class?

Options

  • A@isTest (SeeAllData-true)
  • B@FreTest
  • C@TestSetup
  • D@StartTest

How the community answered

(22 responses)
  • A
    5% (1)
  • B
    5% (1)
  • C
    91% (20)

Why each option

The `@TestSetup` annotation method should be used to create common test records once for all test methods within a test class, optimizing test execution and setup time.

A@isTest (SeeAllData-true)

`@isTest(SeeAllData=true)` allows access to organization data, which is generally discouraged in unit tests for isolation and predictability; it does not create test data but exposes existing data.

B@FreTest

`@isTest` (or `@Test`) is used to define a test class or test method, but `@TestSetup` is the specific annotation for setting up data that should be available to multiple test methods.

C@TestSetupCorrect

The `@TestSetup` annotation is specifically designed to create common test data that is inserted once and then available to all test methods in the test class, which is more efficient than creating data in each test method or using SeeAllData=true.

D@StartTest

`@StartTest` marks the point where governor limits are reset, and processing time starts counting, but it does not create test records.

Concept tested: Apex test data setup

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

Topics

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

Community Discussion

No community discussion yet for this question.

Full PDI Practice