You need to sign in to do that
Don't have an account?

How to write test method for this send email method?
Visualforce code:
<apex:form ><br />
<apex:outputLabel value="Subject" for="Subject"/>:<br />
<apex:inputText value="{!subject}" id="Subject" maxlength="80"/>
<br /><br />
<apex:outputLabel value="Body" for="Body"/>:<br />
<apex:inputTextarea value="{!body}" id="Body" rows="10" cols="80"/>
<br /><br /><br />
<apex:commandButton id="sendEmail" value="Send Email" action="{!send}" />
</apex:form>
Apex Code:
public PageReference send() {
// Define the email
Messaging.SingleEmailMessage email = new Messaging.SingleEmailMessage();
String[] addresses = new string[]{'richard@supremetechnologies.in'};
Messaging.reserveSingleEmailCapacity(addresses.size());
// Sets the paramaters of the email
email.setSubject( subject );
email.setToAddresses( addresses );
email.setPlainTextBody( body );
// Sends the email
Messaging.SendEmailResult [] r =
Messaging.sendEmail(new Messaging.SingleEmailMessage[] {email});
return null;
}
@IsTest
private class testClass {
//test send method
private void testMethod testSend(){
Class controller = new Class(); // where class is the name of class in which Send() method is defined.
@test.startTest();
PageReference page = controller.Send();
System.assert(page == null);
//validate other things such as user, addresses, logic.
@test.stopTest();
}
}
hope this will help you.