You need to sign in to do that
Don't have an account?
Sheeba Narayanan 7
How to write testmethod for getDetails() here.
public class addressDetails{
public String latitude {get;set;}
public String longitude {get;set;}
........
}
public addressDetails getDetails(String strAddress)
{
Http http = new Http();
HttpRequest request = new HttpRequest();
IF (strAddress!=null){
strAddress=strAddress.replaceAll(' ', '+');
addressDetails addr=new addressDetails();
if (latitude!='') { addr.latitude=latitude;}
if (longitude!=''){ addr.longitude=longitude;}
........................
System.debug('Value of adddress is here : ' +addr);
return addr;
}
i need your help to write a test class for this
How to write testmethod for getDetails() here.
public class addressDetails{
public String latitude {get;set;}
public String longitude {get;set;}
........
}
public addressDetails getDetails(String strAddress)
{
Http http = new Http();
HttpRequest request = new HttpRequest();
IF (strAddress!=null){
strAddress=strAddress.replaceAll(' ', '+');
addressDetails addr=new addressDetails();
if (latitude!='') { addr.latitude=latitude;}
if (longitude!=''){ addr.longitude=longitude;}
........................
System.debug('Value of adddress is here : ' +addr);
return addr;
}
All Answers
I saved your code as below.
public class addressDetails{
public String latitude {get;set;}
public String longitude {get;set;}
public addressDetails getDetails(String strAddress)
{
addressDetails addr=new addressDetails();
Http http = new Http();
HttpRequest request = new HttpRequest();
if(strAddress!=null){
strAddress=strAddress.replaceAll(' ', '+');
if (latitude!='') {
addr.latitude=latitude;
}
if (longitude!=''){
addr.longitude=longitude;
}
System.debug('Value of adddress is here : ' +addr);
}
return addr;
}
}
The test class as below
@isTest
public with sharing class addressDetails_TestMethod{
static testMethod void addressDetails_TestMethod() {
Test.startTest();
addressDetails mAD=new addressDetails();
mAD.latitude='13.082680';
mAD.longitude='80.270721';
mAD.getDetails('100,YorkHill Drive, Annandale, VA, USA') ;
Test.stopTest();
}
}
It gives 100% coverage.
Best Regards
Jay
Thanks much for your reply. Here am getting this error while running test "Methods defined as TestMethod do not support Web service callouts" .
This line is making the error mAD.getDetails('100,YorkHill Drive, Annandale, VA, USA') ;
FYI am coping my class again.
public class AutocompleteAddressForm {
Public String latitude{get;set;}
Public String longitude{get;set;}
public class addressDetails{
public String latitude {get;set;}
public String longitude {get;set;}
}
public addressDetails getDetails(String strAddress)
{
Http http = new Http();
HttpRequest request = new HttpRequest();
IF (strAddress!=null){
strAddress=strAddress.replaceAll(' ', '+');
addressDetails addr=new addressDetails();
if (latitude!='') { addr.latitude=latitude;}
if (longitude!=''){ addr.longitude=longitude;}
System.debug('Value of adddress is here : ' +addr);
return addr;
}}
}
Thanks
Sheeba