+ 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);
	}
}