You need to sign in to do that
Don't have an account?
![Lee.ax1423 Lee.ax1423](https://dfc-org-production.my.site.com/img/userprofile/default_profile_45_v2.png)
Unit test cases
Hi,
I am facing problem with unit test cases.....Recently i have integrated salesforce with outer environment.
but the problem is i got the test failure message while writing unit test cases for that.
System.NullPointerException: Attempt to de-reference a null object
Class.SendSMSHttpContact.<init>: line 9, column 1 Class.TestSendSMS.testUnas1: line 15, column 1
Code is:
public class SendSMSHttpContact {
private final Contact contact;
private final String user='some name';
private final String senderID='some';
public String receipientno{get;set;}
private final String dcs='0';
public String msgtxt{get;set;}
public String msg = msgtxt.replace(' ','%20');
private final String state='0';
String endpoint = 'sample url';
public SendSMSHttpContact(ApexPages.StandardController controller) {
this.contact = (Contact)controller.getRecord();
}
public PageReference SendSMS() {
if (contact.MobilePhone != null) {
receipientno = contact.MobilePhone;
receipientno = receipientno.replace('+','');
receipientno = receipientno.replace(' ','');
receipientno = receipientno.replace(')','');
receipientno = receipientno.replace('(','');
receipientno = receipientno.replace('-','');
//construct an HTTP request
HttpRequest req = new HttpRequest();
req.setMethod('GET');
req.setEndpoint(endpoint+'?user='+user+
'&senderID='+senderID+
'&receipientno='+receipientno+
'&dcs='+dcs+
'&msgtxt='+msg+
'&state='+state);
//send the request
Http http = new Http();
HttpResponse res = http.send(req);
//check the response
if (res.getStatusCode() == 200) {
Task smsTask = new Task (Type='SMS',
WhoID = contact.id,
Status = 'Completed',
ActivityDate = System.today(),
Description = msg.replace('%20',' '),
Subject = 'SMS Sent'
);
try {
insert smsTask;
} catch (System.Dmlexception e) {
System.debug('Error: Unable to insert task: ' + e);
}
PageReference pg = new PageReference('/'+smsTask.Id);
return pg;
} else {
//do something
}
}
else {
//do something
}}}
unit test coding is:
@isTest
private class TestSendSMS{
private static testMethod void testUnas1(){
String endpoint='http://google.com';
Contact con = new Contact();
con.LastName = 'test';
con.MobilePhone ='12345';
insert con;
ApexPages.StandardController controller = new ApexPages.StandardController(con);
SendSMSHttpContact test = new SendSMSHttpContact(controller);
system.assertEquals(Page.success,test.SendSMS());
}}
i am in basic stage in writting unit test cases.
can you help me to write unit test case for this.
Past two days onwards i am searching for this.
can any one help me to get out of this.!!!!!