0

Few questions creating some confusion for me:

  1. Do we'v to write ALL SOQL and DMLS before test.start or after test.start method ? For e.g in case of DMLs, If I'm creating test Data for an object and populating a list(say list of Accounts). Should insert DML operation of list , occur before test.start or after test.start?

  2. Suppose my test class has 20 test methods. each having 5-6 queries outside test.start and test.stop . Would it give 100 SOQL error on running test class ?

  3. Suppose I've 20 test classes each having 1 testmethod. Each test method has 5-6 queries outside test.start and test.stop. while deploying code when all test classes will run, would I get 100 SOQL issue ?

Thanks !

1 Answer 1

2

1) Best practice is to set up and load all your data for your test method outside the start/stop methods. In between really you should be testing your code, not creating data.

2) Each time Test.startTest() is called, the governor limits are reset. So the answer is you won't hit the 100 SOQL queries limit

3) Same as above

2
  • Thanks for Comments. It helps. For point 1 , if I will write DML outside start/stop method. Isn't there is a possiblity if I've 100s of test classes, that will hit related governer limits( say 150 DML statement issue). Similary, Also For Point 2 and 3, what happens if suppose , Test.start and test.stop are not present in any TestMethods. I'm guessing, I'll hit governer limit(100 SOQL error) in both cases. Just like to confirm Feb 25, 2015 at 7:32
  • Each test method runs separately with a fresh set of governor limits. Here is why you should be using startTest() and stopTest() - salesforce.com/us/developer/docs/apexcode/Content/… Feb 25, 2015 at 22:43

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .