Skip to Content

Salesforce CRT-450: Usage and Benefits of @testSetup Annotation in Apex Test Class

Learn about the correct usage of the @testSetup annotation in Apex test classes, its incompatibility with @isTest(SeeAllData=True), and how it helps create reusable test data for improved performance and reduced code duplication.

Table of Contents

Question

Which two statements are true about using the @testSetup annotation in an Apex test class? (Choose two.)

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.

Answer

A. The @testSetup annotation is not supported when the @isTest(SeeAllData=True) annotation is used.
D. In a test setup method, test data is inserted once and made available for all test methods in the test class.

Explanation

The correct statements about using the @testSetup annotation in an Apex test class are options A and D.

A. The @testSetup annotation is not supported when the @isTest(SeeAllData=True) annotation is used. This is true because the @testSetup method is designed to create test data in isolation, while @isTest(SeeAllData=True) allows access to org data, which conflicts with the purpose of @testSetup.

D. In a test setup method, test data is inserted once and made available for all test methods in the test class. The @testSetup method runs once before all test methods in the class, and the data created is accessible to all test methods, reducing code duplication and improving performance.

Option B is incorrect because records created in the @testSetup method can be updated in individual test methods.

Option C is incorrect because the @testSetup method runs only once before all test methods, not once for each test method, and does not count towards system limits for each test method.

Salesforce Certified Platform Developer I CRT-450 certification exam practice question and answer (Q&A) dump with detail explanation and reference available free, helpful to pass the Salesforce Certified Platform Developer I CRT-450 exam and earn Salesforce Certified Platform Developer I CRT-450 certification.