I'm trying to understand something so I can use @testSetup annotation wisely. As i read here:
By setting up records once for the class, you don’t need to re-create records for each test method. Also, because the rollback of records that are created during test setup happens at the end of the execution of the entire class, the number of records that are rolled back is reduced
But if you run a test class, you can see that all of the DMLs are recreate for each test method and not just once.
So what is the purpose of using it if I need to add an extra SOQL to retrieve the data I created in each test method? why not just using it in the test class itself and use it directly? just to reduce a code duplication?
Edit: Seems like I was confused because of what I read here:
If a test class contains a test setup method, the testing framework executes the test setup method first, before any test method in the class.
Thanks for your comment Phil.
@testSetupfrom consuming governor limits for your test methods is to use
@testSetupmethod. Turns out that you can use that in
@testSetupand still be able to use it in each individual test method.