Salesforce Platform Developer I (legacy) — Question 198
Which two statements are true about using the @testSetup annotation in an Apex test class? (Choose two.)
Answer options
- A. The @testSetup annotation is not supported when the @isTest(SeeAllData=True) annotation is used.
- B. Records created in the test setup method cannot be updated in individual test methods.
- C. A method defined with the @testSetup annotation executes once for each test method in the test class and counts towards system limits.
- D. In a test setup method, test data is inserted once and made available for all test methods in the test class.
Correct answer: A, D
Explanation
The correct answers are A and D. Answer A is correct because the @testSetup annotation cannot be used when the @isTest(SeeAllData=True) annotation is present, as it would conflict with the test data management. Answer D is accurate since the purpose of the @testSetup method is to insert test data once and share it across all test methods, enhancing efficiency. Answers B and C are incorrect; B is wrong because records from the setup can be updated in test methods, and C is incorrect because the @testSetup method executes only once for the entire test class, not once per test method.