Find your content:

Search form

You are here

Can/should we use assert statement in a test class for batch processes?

 
Share

I have a Batch process which updates a field on Account. I have also written a test class for it. I have an assert statement to check if the field is getting updated.

Unfortunately this assert fails, this i would think is because the batch probably doesnt get executed immediately. Is there a way confirm that the batch is executed and only then do the asserts.

Thanks


Attribution to: Prady

Possible Suggestion/Solution #1

The answer is to enclose the running of the batch file within startTest and StopTest methods

 System.Test.startTest();
   BatchClassName bc= new BatchClassName ();
    Database.executeBatch(bc, 200);
 System.Test.stopTest();

Attribution to: Prady
This content is remixed from stackoverflow or stackexchange. Please visit https://salesforce.stackexchange.com/questions/5073

My Block Status

My Block Content