+ Start a Discussion
JameslongJameslong 

NEED HELP IN A SIMPLE TEST CLASS.....PLEASE

Hi ,

 

I am writing a test class fo rthe follwing integration class and my code covers 90%.

 

But I want to know if this is the right test class or not.

 

CODE:

 

public with sharing class OpportunityUpdateIntegration {

@future (callout=true)

public static void runjob(String username, String password, String jobName, String jobType) {
system.debug('inside ');
HttpRequest req = new HttpRequest();
HttpResponse res = new HttpResponse();
Http http = new Http();

req.setEndpoint('https://app.informaticaondemand.com/saas/api/1/runjob?username='+EncodingUtil.urlEncode(username, 'UTF-8')+
'&password='+EncodingUtil.urlEncode(password, 'UTF-8')+
'&jobName='+EncodingUtil.urlEncode(jobName, 'UTF-8')+
'&jobType='+EncodingUtil.urlEncode(jobType, 'UTF-8'));
req.setMethod('POST');

try
{
res = http.send(req);
}
catch(System.CalloutException e)
{
System.debug('Job Error: '+ e);
System.debug(res.toString());
}
}
}

 

TEST CLASS:

@istest
public class OpportunityUpdateIntegration_test{
static TestMethod void OpportunityUpdateIntegration_test(){
//data preparation
//insert opportunity test records
opportunity opy = new opportunity(Name = 'test opp',stagename = 'closed won',closedate=date.parse('1/1/2020'));
insert opy;
//Assert the inserted test record
system.assertequals(opy.name,'test opp');
OpportunityUpdateIntegration oui = new OpportunityUpdateIntegration();
}
}

 

Please comment on the test class if it is correct or not.

 

Thanks

JL

Best Answer chosen by Admin (Salesforce Developers) 
osamanosaman

You are not covering runjob method in the test method. And also you need to put condition Test.isRunningTest() before calling the web service as test methods don't support callouts.

 

 

All Answers

osamanosaman

You are not covering runjob method in the test method. And also you need to put condition Test.isRunningTest() before calling the web service as test methods don't support callouts.

 

 

This was selected as the best answer
JameslongJameslong

Hi,

 

That worked. Tahnks for the clarification Osaman.

 

Thanks

JL