I have a test setup method in my test class:
class someTest {
static boolean ok;
@testSetup
static void setupTestData() {
...
ok = insertSomeTestData();
}
static boolean insertSomeTestData() {
// ...
return true;
}
@isTest
static void testInsertData() {
System.debug('ok:' + ok);
...
}
}
When setup and test methods are executed, variable ok is null.
Why isn't it initialized in setup?
Best Answer
Because then those setup items wouldn't be fresh for each of your test methods.
This is by design.
@TestSetup
should be used to create the data you need across your test methods. So in your methods you will need to query for the data that you have built and inserted in your test setup.Per Josh Kaplan (Salesforce project management):
Link to Comment