"Use test setup methods (methods that are annotated with @testSetup) to create test records once and then access them in every test method in the test class."
"...Records that are created in a test setup method are available to all test methods in the test class and are rolled back at the end of test class execution. If a test method changes those records, such as record field updates or record deletions, those changes are rolled back after each test method finishes execution. The next executing test method gets access to the original unmodified state of those records."
The B option is too generic and may or may not be true. Option D is more specific that @testsetup method execute only once for the test class and so all insertions in side the method happen only once.
A. The @testSetup annotation cannot be used when the @isTest(SeeAllData=True) annotation is used.
> YES "If the test class or a test method has access to organization data by using the @isTest(SeeAllData=true) annotation, test setup methods aren’t supported in this class."
B. Test data is inserted once for all test methods in a class.
> YES "create test records once"
C. Records created in the @testSetup method cannot be updates in individual test methods.
> NO "If a test method changes those records, such as record field updates or record deletions, those changes are rolled back after each test method finishes execution." > so we the test method can update those records.
D. The @testSetup method is automatically executed before each test method in the test class is executed.
> NO "those changes are rolled back after each test method finishes execution." > it's not re-executed since it's not re-inserted, only what has been changed is rolled back.
source:
https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_testing_testsetup_using.htm
A. When @isTest(SeeAllData=True) is used, you're accessing org data in your test, and @testSetup is designed to isolate test data creation. They shouldn't be used together.
B. The main advantage of @testSetup is to create test data once and then use this data in multiple test methods in the test class, reducing repetitive data creation and making tests run faster. The @testSetup method runs once before any test method in the class. Then, each test method runs, starting with a fresh copy of the data created in the @testSetup method. This ensures each test method runs with the same initial state.
Correct answer is A and B.
C and D are incorrect as the individual test methods can change the values, the changes just don't persist after the test method ends. The code in the @testSetup section is run once at the start of the class, each method can do what it likes with the test data, and the changes are rolled back to the original status when each test method ends.
You sure that D is correct option?
test setup creates records before test methods of the same class are executed and if any test method updates the data it will just rollback the changes. There is nothing about reinserting the data before each test method of the same class.
I would say that A and B are correct answers
It will create them once, and simply use checkpoints to roll back after once test method is finished, it will not create new data.
upvoted 1 times
...
...
Log in to ExamTopics
Sign in:
Community vote distribution
A (35%)
C (25%)
B (20%)
Other
Most Voted
A voting comment increases the vote count for the chosen answer by one.
Upvoting a comment with a selected answer will also increase the vote count towards that answer by one.
So if you see a comment that you already agree with, you can upvote it instead of posting a new comment.
noox
Highly Voted 2 years, 11 months agotapasroy
2 years, 6 months agotapasroy
2 years, 6 months agoSpecer
Most Recent 4 weeks agoNourelhouda101
1 month agoskhan6525
1 year, 2 months agoNand072
1 year, 2 months agoKF1TZ
1 year, 2 months ago1vanTT
1 year, 8 months agoEmperorTuna
1 year, 8 months agoapuchowdhury80
1 year, 10 months agoNand072
1 year, 2 months agoApexMike
2 years, 1 month agoishanjn05
2 years, 3 months agoJackieTso
2 years, 6 months agoBarbBarb
3 years ago21012023
1 year, 9 months ago