You need to sign in to do that
Don't have an account?
Luke Osmundson 2
Test now failing in production
A long working Test Class of mine is now failing in production due to too many SOQL calls on the second to last call. I tried adding in test.start() and test.stop() functions, which should have reduced the number of calls by 22, but it still fails at what appears to be the exact same place when I try and push the test class. I can't even work on anything else until this resolves, as it causes everything I try to push to fail. Does anyone have any clue what might be happening?
This is currently something that i too am faced with. Seems like test.StartTest and test.StopTest() do increase your governor limits within the test start/stop block but dont reset it after the stop call. This is undocumented (or is unclear to me from the documentation upon reading) but it seems like this is the issue. I got arround this by placing my query/dml inside of the start/stop block and it seems to work just fine for me.
Hope this helps!
AM
The code before test.StartTest has all the same limits as a normal code execution. test.StartTest resets these limits back to 0 and gives you a full set of limits for your actaul test code. As far as I know the statements after test.StopTest are counted with your test code.
It is true that Test.startTest reset the limits to 0, but may be inside your test method you are doing multiples calls to the same method as example :
Test.startTest();
Controller ctrl = new Controller(myCase);
ctrl.save();
myCase.field__c = 'xxx';
update myCase.
ctrl.save();
myCase.field__c = 'yyyy';
update myCase;
ctrl.save();
....
Test.stopTest();
You will hit limits like this if it's the case since there are Triggers which means cumulative SOQL Queries. i suggest to split into several test Methods where you can test Case by case.