You need to sign in to do that
Don't have an account?
How to get 100% code coverage for rest web service
Hi all ,
I have rest resource as follows
(Provider__c custome object contains first_name__c,last_name__c,provider_specilty__c fields)
@RestResource (urlMapping = '/Provider')
global with sharing class ProviderRestResource {
global class ProviderDetails{
String fName,lName,primarySpeciality;
}
@HttpGet
global static List<ProviderDetails> getProviderDetails (){
List<ProviderDetails> pList = new List<ProviderDetails>();
for (Provider__c p : [select first_name__c,last_name__c from Provider__c ]){
ProviderDetails pd = new ProviderDetails();
pd.fName = p.first_name__c ;
pd.lName = p.last_name__c ;
pList.add(pd);
}
return pList;
}
@HttpPost
global static List<ProviderDetails> searchProviderDetails (String s){
List<ProviderDetails> pList = new List<ProviderDetails>();
for(Provider__c p : [select first_name__c,last_name__c,primary_specialty__c from Provider__c where first_name__c =: s]){
ProviderDetails pd = new ProviderDetails();
pd.primarySpeciality = p.primary_specialty__c ;
pd.fName = p.first_name__c ;
pd.lName = p.last_name__c ;
pList.add(pd);
}
return pList;
}
public static testMethod void testProvider(){
getProviderDetails();
searchProviderDetails('s');
}
}
In this am getting nearly 70% code coverage so please help in improving test method to get 100% code coverage.
U need some mock responses for testing. Chekc the below link on how to generate those.
http://www.salesforce.com/us/developer/docs/apexcode/Content/apex_classes_restful_http_testing_httpcalloutmock.htm