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
DeveloperDeveloper 

please help me in bellow code, i want test class

public static void sendEmail(String messageBody,String sSubject){
           
       try{
        
        String sRecipantName = UserInfo.getUserEmail();
        String[] sendingTo = new String[]{sRecipantName};
        Messaging.SingleEmailMessage oMail = new Messaging.SingleEmailMessage();
        String sBody = messageBody ;
        oMail.setHtmlBody(sBody);
        oMail.setSubject(sSubject);
        oMail.setBccSender(false);
        oMail.setSenderDisplayName('noreply@salesforce.com');
        oMail.setSaveAsActivity(false);
        oMail.setToAddresses(sendingTo);
        Messaging.sendEmail(new Messaging.SingleEmailMessage[] { oMail });
       
        }catch(Exception ex){
            system.debug('Exception while Sending Mail ' + ex.getMessage());
        }

    }

}
 
Best Answer chosen by Developer
Eric PepinEric Pepin
@isTest
private class testEmail {
	static testmethod void testEmailSend() {
		string body = 'Test body';
		string subject = 'Test subject';
		
		integer beforeInvocations = Limits.getEmailInvocations();
		
		Test.startTest();

		[ClassName].sendEmail(body, subject);
		
		Test.stopTest();
		
		integer afterInvocations = Limits.getEmailInvocations();
		system.assertNotEquals(beforeInvocations, afterInvocations);
	}
}