Questions tagged [httpcalloutmock]

The HttpCalloutMock interface enables sending fake responses when testing HTTP callouts in Salesforce.

Filter by
Sorted by
Tagged with
0
votes
0answers
15 views

Test batch with multiples Callouts - HTTPMock [duplicate]

I have a Class that integrate Api , there are many Callouts in there. And I have a Batch Class that running on functions of this class. My question is about the test class. test class: @...
0
votes
1answer
23 views

How can I return HttpResponse after calling a class which implements Queueable

As described in the title, I have a class which implements the Queueable interface, for each item it sends an http request and I would like to get the response back and use it. My problem is that I ...
1
vote
2answers
76 views

System.TypeException: Mock object doesn't implement the supplied interface. Tried to add different methods in the mock class

I created a mock class which has different methods WHen I tried to get the different response based on my scenarios. Im getting the error like 'System.TypeException: Mock object doesn't implement ...
0
votes
1answer
17 views

How to mock test a rest API implementation

I have a method public static Map<String, Object> createNewAccessToken() { Map<String, Object> access_token = null; HttpRequest req = new HttpRequest(); req....
2
votes
1answer
103 views

System.XmlException: start tag unexpected character =

This is the full error: System.XmlException: start tag unexpected character = (position: END_TAG seen ...<source> Bicycling</source><media:contenturl=... @1:688) So from my ...
0
votes
0answers
47 views

Mock HTTP Call Out In Test to Return XML

I am very new to HTTP Callouts and now I am in the testing phase. My HTTP Callout returns XML This is the link. I input a company already, soulcycle, in case anybody wanted to see what was being ...
1
vote
1answer
49 views

Test error condition in finish() method of Batchable class

Trying to figure out how to test error condition in the finish() method of this Batchable class. I am testing the error condition in the execute() method by calling it separately in the test and ...
1
vote
1answer
36 views

Test error condition in batch class with callouts

I have an Apex class with a callout (oregonDistricts.apxc) and I have two tests written that test both the success and error conditions. These tests are passing and the class has 100% code coverage. ...
4
votes
1answer
46 views

How to confirm one of many HttpCalloutMock has been used

If I load multiple HttpCalloutMock's when settings up a test: Test.setMock(HttpCalloutMock.class, MockFactory.create()); And I am using a MultiRequestMock implementation: public without sharing ...
0
votes
0answers
33 views

Apex Testing HttpCalloutMock failing

The method is for testing a class that use a soap envelope to check if an address exists and if it does return true, otherwise it returns false. It implements Jennifer Symonds xpath to verify the ...
12
votes
1answer
813 views

How do I unit test code that includes a callout?

This is a canonical question and answer developed by the community to help address common questions. If you've been directed here, or your question has been closed as a duplicate, please look through ...
0
votes
0answers
27 views

Get JSONException with valid JSON. How to figure out what's wrong?

I have a bit of JSON coming from a mock that needs to de deserialized into an object. The JSON itself is perfectly valid. It has been validated by multiple services, and they all say it looks legit. ...
0
votes
1answer
126 views

Is getContent not supported in unit tests, even if HttpCalloutMock is used?

I have created REST Service to return content from supplied image URL. In @post method of REST Service, I have used page.getContent() method to retrieve image content. My REST Service is working fine. ...
1
vote
1answer
249 views

Methods defined as TestMethod do not support Web service callouts - Unit Test [duplicate]

We have a custom object called 'support' - we have process builder configured for this object. in one of the process builder action it will invoke Apex (Invocable Method). This will trigger a callout ...
0
votes
1answer
23 views

How to test 'throw new MyException()' in HttpResponse Callout?

I always get an Fail when try to test the negative scenario. How can I fix it? Sorry, I'm just learning. Callout: public class MyException extends Exception {} public class Token{ public String ...
0
votes
1answer
30 views

How can I test my Web Token and posted record from Post Callout?

I try to use HttpCalloutMock to test my post callout. But I become System.NullPointerException: Attempt to de-reference a null object. I need to test and web token, and posted object. I'm just ...
-1
votes
1answer
394 views

How to fix Attempt to de-reference a null object in test for Post Callout?

I become an error System.NullPointerException: Attempt to de-reference a null object in my test: public class Token{ public String accessToken{get;set;} } public static String accessTokenBody(){ ...
1
vote
1answer
167 views

How can I test Post Callout with web token's access? HttpCalloutMock

My POST Method (data for web token - is my custom object's fields): public class Token{ public String accessToken{get;set;} } public static String accessTokenBody(){ //our web token (data is in ...
0
votes
1answer
162 views

How to test access token for HTTP callouts?

I have an access token for my HTTP callouts. How can I test it if I wanna use Static Resource? But I can also use the HttpCalloutMock Interface. it doesn't matter My access token is in custom object. ...
1
vote
1answer
88 views

How can I test Callouts with HttpCalloutMock?

How can I test this method? I try the test code from trailhead but can't make any coverage. Callout: public class Token{ public String accessToken{get;set;} } public static HttpResponse ...
0
votes
1answer
222 views

How to avoid: Error uncommitted work pending in my testclass

I am doing do a callout trough a processbuilder with a future call. Before I do the call I get some variables from a custom setting. When I do an insert in my testclass for my custom setting I get the ...
0
votes
1answer
583 views

Script-thrown exception in Test class for Batch apex callout

I have a batch class which makes multiple http callouts to an HR system and then with the absences returned checks for existing absences and upserts. However when I try and run test class for the ...
0
votes
2answers
55 views

Distance calculation API

Below is the code for distance calculation using matrix api. I have declared all the variables as private and called HTTP get method for this. in the log of the code I got an error Method does not ...
0
votes
1answer
34 views

Test Class for testing controller twice

I have a test class below that is successful and covers accessing my controller with a callout: @isTest static void testUpdateOfPack(){ MockPackageService mockRes = new MockPackageService(); ...
3
votes
1answer
800 views

Unit Test Error: Methods defined as TestMethod do not support Web service callouts

Firstly, I know what this message is trying to tell me: Methods defined as TestMethod do not support Web service callouts And I believe I have set up all the HttpCalloutMock's correctly, because ...
3
votes
2answers
810 views

Unit Test: System.CalloutException: You have uncommitted work pending. Please commit or rollback before calling out

BACKGROUND I am testing a method that results in two external calls out to an API. I have this Apex unit test: @isTest public static void createInvoice_Success(){ // arrange ...
0
votes
2answers
311 views

Test class for Scheduled Batch class making a callout in the start method

I have two classes - BatchClass and SchedulerClass. Batch class makes an API callout in the start method and return the list of records to insert. This class is scheduled with the help of ...
-1
votes
1answer
28 views

How to create an external databate to test rest API classes

I have been doing some trailheads for REST api's I managed to create a callout class with a mock response based on a static resource, whitch gives me 100% coverage. I would like to see my Callout in ...
0
votes
1answer
95 views

Test failure 7% for HTTP Call out [closed]

I am not sure why I am getting the two errors I labeled below during the http send in the first class or in the Mock Impl class when I assert the endpoint. public class ProcessHandlerShowAccounts { ...
1
vote
2answers
487 views

Test class get error System.CalloutException: You have uncommitted work pending. Please commit or rollback before calling out

I have almost tried all solutions available on internet but i still face the error. my Test class code is @isTest private class RegisterTest { @isTest static void existingUserCheck() { ...
1
vote
1answer
90 views

System.CalloutException: You have uncommitted work pending error when creating testing user and testing callout

There are a lot of questions related to "System.CalloutException: You have uncommitted work pending" errors, but could not find solution for following use case: Basically, a static method in the test ...
0
votes
1answer
105 views

Basic Mock Test Coverage Help

I think this will be a easy fix, I am sure it is something I am just overlooking at the end of the day. I created a mock class to test my callouts. It is called SingleRequestMockClass.cls, I got the ...
0
votes
2answers
79 views

Keep Failing Trailhead AnimalCallouts Tutorial

I am just copying and pasting an exercise in the Trailhead API Integration tutorial and the system.assertEquals(expectedValue,actualValue) line keeps failing between the mocked JSON I am feeding ...
1
vote
1answer
172 views

System.NullPointerException: Attempt to de-reference a null object test class

I have a class that makes a callout, it works fine, but the test class fails @isTest global class FinacleMockResponseGenerator2 implements WebServiceMock { global void doInvoke( Object ...
-1
votes
2answers
147 views

System.CalloutException: Unauthorized endpoint, please check Setup->Security->Remote site settings. endpoint [duplicate]

Try to do a mock callout internally on custom button click and also added the instance in remote site setting. @future(callout=true) webservice static void generatePDF(Id idList, String sessionId) { ...
0
votes
2answers
46 views

Can a Test Class have no member variables?

I am testing some HTTP callouts in Apex and instead of passing a newly created MyHttpCalloutMockImpl object in the test method every time, thought of declaring the same at class level and reusing it ...
-5
votes
1answer
598 views

Test class error for callout method, System.JSONException

I am only calling my method in Test Class and getting : System.JSONException: Invalid numeric value: Leading zeroes not allowed at input location [1,2] My callout method is: global static String ...
-4
votes
1answer
32 views

Callout Unit Test Need help in getting code coverage its getting to 46%

I have written a Callout Class Called RestCallout which makes Callout to an end point, get the httpResponse as xml and from the body of response gets different elements and updates the database. For ...
-2
votes
1answer
151 views

Getting error while writing test class

When i am trying to write a test class for my class (NameProjectTDfromAccolade).. I am getting the below error System.TypeException: Invalid conversion from runtime type List to Map on line ...
1
vote
1answer
747 views

HttpCalloutMock that returns a null response

I have a simple class that send an HTTPRequest and gets an HTTPResponse. I wanted to create a NullResponseMock that implements HttpCalloutMock and returns null, but I get an exception as: System....
3
votes
1answer
272 views

Testing future Callouts

I am trying to make a future callout sending email name etc from a trigger when a lead is created which is working. The problem is Testing. I am not sure how to go about making this work. I have been ...
3
votes
4answers
361 views

Is it mandatory to write HttpCalloutMock?

I'm doing some service calls of which I do not have anything to do with the response. So it's most of like fire and forget thing. Below is my abstract implementation class A { public void Setup()...
0
votes
1answer
101 views

facing System.CalloutException for HTTP response in test class

I'm facing "System.CalloutException: You have uncommitted work pending. Please commit or rollback before calling out" Here is my codes: (Adding only the relevant code) Callout Class which ...
0
votes
2answers
688 views

HTTP Callout Test Error

I'm trying to push some code from one of our sandboxes to production. Class: public class CloudtoDevOps { @future (callout=true) public static void sendNotification(String ClientID, ...
0
votes
1answer
686 views

Test class for MetadataService

Can anyone help me understand how to write a test method/or generate mock response when using MetadataService.cls Here is the line which I am trying to cover MetadataService.ApprovalProcess ...
1
vote
1answer
461 views

How can I write test classes for HTTP callouts which has checks for multiple status codes?

createFolderResponse = SharePoint_IntegrationHandler.createFolder(null,parentFolder); if(createFolderResponse.getStatusCode() == 200 || createFolderResponse.getStatusCode() == 201){ //----------...
0
votes
1answer
320 views

test class for the @auraenabled method that only call on button clicks

I am facing issue in writing test class that has 1 method which only executed when the lightning buttons get clicked.please suggest on this issue. Any help would be appreciated.
0
votes
2answers
283 views

Include HttpCalloutMock in TestSetup

I am writing a testclass that has to perform a callout. The callout returns a JSON string that is used to update a custom object in salesforce. This custom object has a master-detail relationship ...
0
votes
0answers
507 views

Callout in test method not returning mock response

I am trying to write a test class for testing an HTTP callout. Test class compiles without errors. However, I am not getting the mock response inside. Below is the relevant parts of my code. ...
7
votes
2answers
597 views

How to set an HttpCalloutMock to reply differently on subsequent requests to the same endpoint?

I'm building a Queueable that consumes an Azure service bus queue. Every call to the endpoint gives me one message so I keep on calling that same endpoint until I get a 204. The method that calls the ...