You need to sign in to do that
Don't have an account?
How to increase the code coverage in the Test Case
Hi All,
We have written an application to implement SMS feature in salesforce. The application is running successfully, but when I am writing test case, the test case is successful but the code coverage is 54%. But, in order to migrate the code we are suppose to have a code coverage of 75 %.
Therefore I request you people to kindly suggest some solution, so that the code coverage is greater than 75 %.
I am posting both the class and testcase, do kindly suggest a solution.
Apex Class
public class DEV_Send_SMS{
private ApexPages.StandardController controller {get; set;}
private task parOrd;
Private account acc;
public DEV_Send_SMS(ApexPages.StandardController Controller) {
this.controller = controller;
parOrd=(task)Controller.getrecord();
}
public Pagereference pageredir() {
task t=[select id, description, Dev_Send_SMS__c, who.type, whoid
from task where id =:parOrd.id and who.type='contact'];
contact c =[select id, name,MobilePhone, phone from contact
where id =:t.whoid];
String s = 'http://www.rediworkz.com/sms/apisendsmsbulk.php?type=0&from=60122173031&to=' + c.MobilePhone + '&text=' + t.Description + '&user=60122173031&pass=rick2345&senderid=VISTA&gateway=9';
return t.Dev_Send_SMS__c == 'yes' ? new PageReference(s) : null;
}
}
TestCase:
@isTest
private class DEV_Send_SMSTestCase
{
static testMethod void MyMethod()
{
Task t1 = new Task();
ApexPages.StandardController con = new ApexPages.StandardController(t1);
Task parOrd = (Task)con.getRecord();
DEV_Send_SMS sms1 = new DEV_Send_SMS(con);
// sms1.pageredir();
}
Note: If I am enabling the last statement in the TestCase (sms1.pageredir();)
I am getting a code coverage of 72% , but the TestCase is getting failed. So kindly provide a solution.
Regards
Arun
Issues with hardcoding usernames and passwords in your URL parameters aside, you certainly need to ensure that you test all methods correctly. However, because your pageredir method includes a http callout, which is not supported by test methods, you need to adjust your code to handle it. Check out the following link for some guidelines. You may also be interested in the Apex Testing Webinar coming up on March 30 (http://www.developerforce.com/events/intro_to_apex_testing_webinar/registration.php?d=70130000000FuN)
http://wiki.developerforce.com/index.php?title=Virtual_Callout_Testing