nerdexam
Salesforce

PDI · Question #148

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

The correct answer is C. @TestSetup. The @TestSetup annotation should be used on a method to create test records once for a test class, making them available to all test methods in that class for efficient and consistent data setup.

Submitted by chen.hong· Apr 18, 2026Testing, Debugging, and Deployment

Question

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

Options

  • A@BeforeTest
  • B@isTest(SeeAllData=True)
  • C@TestSetup
  • D@PreTest

How the community answered

(34 responses)
  • A
    6% (2)
  • C
    91% (31)
  • D
    3% (1)

Why each option

The `@TestSetup` annotation should be used on a method to create test records once for a test class, making them available to all test methods in that class for efficient and consistent data setup.

A@BeforeTest

`@BeforeTest` is not a valid Apex test annotation.

B@isTest(SeeAllData=True)

`@isTest(SeeAllData=True)` allows tests to access existing organization data but does not create new records and is generally discouraged for isolated unit tests.

C@TestSetupCorrect

The `@TestSetup` annotation defines a method that executes once before any test methods in the test class, creating a common set of test records that are then shared and rolled back after each individual test method execution, optimizing test data creation.

D@PreTest

`@PreTest` is not a valid Apex test annotation.

Concept tested: Efficient test data setup with @TestSetup

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

Topics

#Apex Testing#Test Data#@TestSetup

Community Discussion

No community discussion yet for this question.

Full PDI Practice