function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Priyanka ITSPriyanka ITS 

How to Write a test class for batch apex having emailmessage


You can use Test.IsRunningTest() to skip the email and if you want to cover it then to check the sending you can use the Limits.getEmailInvocations method.

  Integer invocations = Limits.getEmailInvocations();

System.assertEquals(1, invocations, 'An email should be sent');

Go over these posts as well:

Peak ParkinsPeak Parkins
Thank For Sharing These Url

I got Solution With The Help Of This Guide (
Brittney PittmanBrittney Pittman
You can test Batch Apex by inserting some sample records in a test class. Then, you can invoke it and verify whether or not the records were modified as planned. Batch Apex allows you to test ( the execute method only once.
rohanmi rohanmirohanmi rohanmi
Test.IsRunningTest(): This is a global method in Salesforce that allows you to check if the code is running in a test context. It's commonly used to skip certain operations or behave differently during unit tests fnaf security breach (
Test.startTest() and Test.stopTest(): These methods are used to delineate the part of your code that you want to measure for governor limits in your test. Any governor limits related to CPU time, DML operations, or email invocations are measured inside this block.