+ Start a Discussion
deepakMdeepakM 

Need 100% code coverage for the class.

hi every one.

 

I need 100% code coverage for the class ,i tried to make a test class but it not covered 100%  just 70%

 

Below is my class as well as test class as under:

 

My Class

 

public class WebServiceSalesforceFeed{
@future (callout =true)
public static void HttpResult(String oppID) {
SalesForceUrl__c sf = SalesForceUrl__c.getValues('AMUrl'); // custom setting objects.
SalesForceUrl__c sf2 = SalesForceUrl__c.getValues('IsSandBox');
HttpRequest req = new HttpRequest();
HttpResponse res = new HttpResponse();
Http http = new Http();
if(sf !=null && sf2!=null)

{
req.setEndpoint(sf.SettingValue__c+'/salesforce/SalesForceFeed?oppid='+oppID+'&IsSanbox='+sf2.SettingValue__c);
}

req.setMethod('GET');

try
{
res = http.send(req);
string result = res.getBody();
System.debug('STATUS:'+res.getStatus());
System.debug('STATUS_CODE:'+res.getStatusCode());

}
catch(System.CalloutException e)
{
System.debug('Callout error: '+ e);
System.debug(res.toString());
}

}

// run WebServiceCallout.testMe(); from Execute Anonymous to test
public static testMethod void testMe() {
WebServiceSalesforceFeed.HttpResult('006d0000006enVK');
}

}

 

 

The Test class

 

@isTest
private class WebServiceSalesFeedTest {

static testMethod void myUnitTest() {

Opportunity opp = new Opportunity();
opp.Name = 'Test Opp';
opp.StageName = 'To Be Searched';
opp.p1_First_Name__c ='A';
opp.p1_Last_Name__c ='D';
opp.p1_Gender__c = 'S';
opp.p1_First_Name__c ='S';
opp.p1_Last_Name__c ='A';
opp.p1_Gender__c = 'D';
opp.DOB_Main_Passenger__c = System.now().date();
opp.Number_of_Passengers__c = 4;
opp.CloseDate = System.now().date();
opp.Departure_Date__c = System.now().date();
opp.Origin_City__c = 'DEL';
opp.Destination_City__c= 'MUI';
opp.Return_Date__c = System.now().date();
opp.AmMessage__c ='testttt';

insert opp;

SalesForceUrl__c sf = new SalesForceUrl__c();
sf.Name ='AMUrl';
sf.SettingValue__c ='test';
insert sf;
SalesForceUrl__c sf2 = new SalesForceUrl__c();
sf2.Name ='IsSandBox';
sf2.SettingValue__c ='test';
insert sf2;

WebServiceSalesforceFeed obj = new WebServiceSalesforceFeed();
WebServiceSalesforceFeed.HttpResult(opp.Id);
WebServiceSalesforceFeed.testMe();
}
}

 

 

As this is custom setting object

 

 SalesForceUrl__c sf = new SalesForceUrl__c(); 

having SettingValue__c is custom fieild.

and two values Name = "amurl" and "SettingValue" having some value

 two values Name = "amurl" and "IsSandBox" having some value

,As i used this  in above code as shown in green line above.

 

 

Please guide me how can i achieve 100% for this class as it was about 80 % covered before i added green lines but i need this.

 

 

Thanks

 

 

 

 

domdickdomdick

Hey,

Can you take a look at the debug log and confirm that there are no other failures while creating the test data?

Also, please share the lines that are not covered. You can get that by clicking on the % coverage against the class name on the UI.

 

Thanks,

deepakMdeepakM

hi

 

i got 85% code coverage but the highlighted black lines are not yet coverd.

 

thanks

domdickdomdick

You may find the answer here