Let this sample code demonstrate what I mean here:
@isTest
public class TestSample
{
public static String tmp;
@isTest
static void Test1()
{
System.debug('tmp in Test1: ' + tmp);
}
@testSetup
static void testPrep()
{
tmp = 'Hello';
System.debug('tmp in prep: ' + tmp);
}
}
Debug result is:
tmp in prep: Hello. tmp in Test1: null
I understand that Salesforce should clear up static variable values after each unit test method run. But it doesn't make much sense to me it should do the same thing after testSetup method is finished.
Is there any particular reason Salesforce is doing so? Or is it a bug of Salesforce?