Salesforce Platform Developer I (legacy) — Question 23
Which two statements are true about using the @testSetup annotation in an Apex test class? (Choose two.)
Answer options
- A. The @testSetup annotation cannot be used when the @isTest(SeeAllData=True) annotation is used.
- B. Test data is inserted once for all test methods in a class.
- C. Records created in the @testSetup method cannot be updates in individual test methods.
- D. The @testSetup method is automatically executed before each test method in the test class is executed.
Correct answer: A, B
Explanation
Option A is correct because the @testSetup annotation is not compatible with @isTest(SeeAllData=True), which allows access to all organization data. Option B is also correct as the @testSetup method inserts test data once, making it available for all test methods in the class. Options C and D are incorrect; records created in @testSetup can be updated in test methods, and the @testSetup method runs only once before all methods, not before each one.