Welcome to ExamTopics
ExamTopics Logo
- Expert Verified, Online, Free.
exam questions

Exam CRT-450 All Questions

View all questions & answers for the CRT-450 exam

Exam CRT-450 topic 1 question 15 discussion

Actual exam question from Salesforce's CRT-450
Question #: 15
Topic #: 1
[All CRT-450 Questions]

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

  • 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.
Show Suggested Answer Hide Answer
Suggested Answer: AB 🗳️

Comments

Chosen Answer:
This is a voting comment (?) , you can switch to a simple comment.
Switch to a voting comment New
noox
Highly Voted 2 years, 11 months ago
Selected Answer: AB
"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."
upvoted 18 times
tapasroy
2 years, 6 months ago
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.
upvoted 2 times
tapasroy
2 years, 6 months ago
So A & D is the correct answer.
upvoted 4 times
...
...
...
Specer
Most Recent 4 weeks ago
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
upvoted 1 times
...
Nourelhouda101
1 month ago
Selected Answer: AB
Right answer : AB
upvoted 1 times
...
skhan6525
1 year, 2 months ago
Selected Answer: BD
Test data are visible for all test methods -> B
upvoted 2 times
...
Nand072
1 year, 2 months ago
Selected Answer: BD
B & D are correct I think, as well as A, so the question is wrong
upvoted 2 times
...
KF1TZ
1 year, 2 months ago
Selected Answer: AB
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.
upvoted 2 times
...
1vanTT
1 year, 8 months ago
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.
upvoted 2 times
EmperorTuna
1 year, 8 months ago
This is correct. People who have suggested that D is correct have not read the answer thoroughly.
upvoted 2 times
...
...
apuchowdhury80
1 year, 10 months ago
Selected Answer: AB
D is not correct as TestSetup execute only once per class
upvoted 2 times
Nand072
1 year, 2 months ago
The D did not suggest that the @TestSetup is executed more than once per class. Read carefully again.
upvoted 1 times
...
...
ApexMike
2 years, 1 month ago
D isn't correct. The code is executed only once before any method is called, and data is rolled back at the end of each method. A and B are correct.
upvoted 3 times
...
ishanjn05
2 years, 3 months ago
Selected Answer: AB
@TestSetup method only execute once per class
upvoted 1 times
...
JackieTso
2 years, 6 months ago
please tell me why b is incorrect?
upvoted 2 times
...
BarbBarb
3 years ago
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
upvoted 3 times
21012023
1 year, 9 months ago
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
...
...
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.

SaveCancel
Loading ...