Crap, I've misread the question! Yes, they're isolated!
There are no equivalents of jUnit's setUp
and tearDown
but each method is independent of other methods. If you need setUp
, you have to write it yourself - create a small private static void prepareTestData()
with all your DML and explicitly call it at the beginning of your test methods.
Actually it might be marked as public - will save you time if you can reference them from other test classes. It's still within a test class so it's unaccessible from regular code and does not count towards Apex storage usage.
There used to work a neat trick that would let you have some kind of "initialization block":
@isTest
private class TestClassName {
private static Acount testAccount;
static {
testAccount = new Account(Name = 'science, baby');
insert testAccount;
}
static testMethod void testMethodName() {
}
static testMethod void testMethodName() {
}
}
This doesn't work anymore :( If you have only 1 test method it should work, but each subsequent one will not see the data crated in this static block.