Remember to wrap the @TestSetup also in Test.startTest() and Test.stopTest() to reset the governor limits.
@TestSetup
static void setupData() {
Test.startTest();
//Create test data
Test.stopTest();
}
This is quite funny since you are not actually starting (and stopping) any tests in the @TestSetup you are only creating test data
It is a common misconception that @TestSetup has it’s own governor limits and that the limits would be reset after the code has been executed in the method. The truth is that the governor limits carry over to the test methods (@IsTest) if they are not reset. There is even an idea to exempt the @TestSetup from governor limit completely, see https://ideas.salesforce.com/s/idea/a0B8W00000GdVeKUAV/remove-governor-limits-on-testsetup-methods

Leave a comment