You need to sign in to do that
Don't have an account?
I am Cover my class 100% but Test class is fail.
MY callout class
public with sharing class XeroCalloutUtility {
public static Xero_Settings__c xeroSettings {
get {
if (xeroSettings == null) {
xeroSettings = Xero_Settings__c.getInstance('Xero');
}
return xeroSettings;
}
set;
}
public static HttpResponse executeCallout (String method, String resourceName, String requestBody) {
system.debug('>>>>>>>>>>xeroSettings '+xeroSettings);
HttpRequest request = new HttpRequest();
request.setMethod(method);
request.setEndpoint(xeroSettings.Endpoint__c + resourceName);
request.setHeader('Accept', 'application/json');
system.debug('>>>>>>>>>>>>>>>>>>request '+request);
if (String.isNotBlank(requestBody)) {
request.setBody(requestBody);
request.setHeader('Content-Type', 'text/xml');
}
request = XeroOAuthUtility.signRequest(request, xeroSettings.Consumer_Key__c);
return new Http().send(request);
}
}
Here is my test class
@isTest
public with sharing class XeroCalloutUtilityTest{
Public Static TestMethod Void Testcallout(){
Test.StartTest();
Xero_Settings__c xeroseting = new Xero_Settings__c();
xeroseting.name = 'testName';
xeroseting.Consumer_Key__c = 'testConsumer';
xeroseting.Endpoint__c = 'www.xero.com';
insert xeroseting;
XeroCalloutUtility.executeCallout(' request.setMethod','request.setEndpoint','request.setBody');
HttpRequest request = new HttpRequest();
String contentType = request.getHeader('Content-Type');
String actualValue = request.getBody();
request.setHeader('Accept', 'application/json');
//HttpResponse response = new HTTP().send(request);
Test.StopTest();
}
}
Any one help me where I am wrong
public with sharing class XeroCalloutUtility {
public static Xero_Settings__c xeroSettings {
get {
if (xeroSettings == null) {
xeroSettings = Xero_Settings__c.getInstance('Xero');
}
return xeroSettings;
}
set;
}
public static HttpResponse executeCallout (String method, String resourceName, String requestBody) {
system.debug('>>>>>>>>>>xeroSettings '+xeroSettings);
HttpRequest request = new HttpRequest();
request.setMethod(method);
request.setEndpoint(xeroSettings.Endpoint__c + resourceName);
request.setHeader('Accept', 'application/json');
system.debug('>>>>>>>>>>>>>>>>>>request '+request);
if (String.isNotBlank(requestBody)) {
request.setBody(requestBody);
request.setHeader('Content-Type', 'text/xml');
}
request = XeroOAuthUtility.signRequest(request, xeroSettings.Consumer_Key__c);
return new Http().send(request);
}
}
Here is my test class
@isTest
public with sharing class XeroCalloutUtilityTest{
Public Static TestMethod Void Testcallout(){
Test.StartTest();
Xero_Settings__c xeroseting = new Xero_Settings__c();
xeroseting.name = 'testName';
xeroseting.Consumer_Key__c = 'testConsumer';
xeroseting.Endpoint__c = 'www.xero.com';
insert xeroseting;
XeroCalloutUtility.executeCallout(' request.setMethod','request.setEndpoint','request.setBody');
HttpRequest request = new HttpRequest();
String contentType = request.getHeader('Content-Type');
String actualValue = request.getBody();
request.setHeader('Accept', 'application/json');
//HttpResponse response = new HTTP().send(request);
Test.StopTest();
}
}
Any one help me where I am wrong
you can't make a callout in test class. create MokeCalloutRequest class. and call this fake callout class in you test class then will work.
use below code for Create SingleRequestMock class.
First Create this class.
use below upadted Testclass code.
Hope this will help you.
Mark Best ANSWER if its work for you.
Thanks
Karthik
All Answers
you can't make a callout in test class. create MokeCalloutRequest class. and call this fake callout class in you test class then will work.
use below code for Create SingleRequestMock class.
First Create this class.
use below upadted Testclass code.
Hope this will help you.
Mark Best ANSWER if its work for you.
Thanks
Karthik
Create fake response, instruct the Apex runtime to send this fake response by calling Test.setMock in your test method.
its Showing the below error
You have uncommitted work pending. Please commit or rollback before calling out
Try to place a Test.StartTest(); after this insert
Hope this will help you .
Thanks
karthik
Hello karthikeyan perumal
Thanks
My test class is passed
I want know more when I am use seealldata=true then class is passed and coverage is 100% and when I am not use(SeeAllData=true) then class is fail and coverage is 57%
How to solve this problem
Thanks
Vikas Rathi
What is the error message you are getting?
Thanks
karthik