You need to sign in to do that
Don't have an account?
joo
Why system.assert() method calling after test.stopTest()
Hi Guys,
As salesforce standard document says:
The Test.stopTest method marks the point in your test code when your test ends. Use this method in conjunction with the startTest method. Each test method is allowed to call this method only once. After calling this method, any post assertions are done in the original context.
I need one urgent help..Can any one tell me why do we use system.assert() method after test.stopTest() ?
Please suggest me and also let me know If I getting things wrong.
Thanks
Joo
Hello,
When test ends, we verify the behavior of code with System.assert methods. For further details refer following documents:
http://www.salesforce.com/us/developer/docs/apexcode/Content/apex_System_System_static_methods.htm
http://www.salesforce.com/us/developer/docs/apexcode/Content/apex_testing_example.htm
Hi Vinita_SFDC,
Thanks for the quick reply.
Yes. You are correct that we write system.assert() to test functional behaviour. Can't we write system.assert() method before test.stopTest() that means inside test.startTest() and test.stopTest()?
Please suggest.
Best regards,
Joo
Hello Joo,
Between test.startTest() and test.stopTest() we get a fresh set of governor limits, here we test for governon limits. After test.stopTest() another execution context starts with new set governor limits.
So if you include your assert statements within test methods, these statements will be counted under apex script statement limit. That is why we write assert statement out of test methods.
test.stopTest() does not introduce a new set of governor limits, it simply goes back to the context previously used before test.startTest().
So if you made 90 SOQL queries before test.startTest() ran, you only have 10 left to make after test.stopTest().
Also, there is no such thing as an Apex "script statement limit". Assert methods can be run quite safely without worrying about limits.