A message from our CEO about the future of Stack Overflow and Stack Exchange. Read now.

Questions tagged [httpcalloutmock]

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

23 questions with no upvoted or accepted answers
Filter by
Sorted by
Tagged with
7
votes
0answers
585 views

How do you use a mock response when calling Auth.JWTBearerTokenExchange.getAccessToken()?

Let's say I have a class like this /** * Example of using JWTBearerTokenExchange to demonstrate issues with testing and mocks */ public class JwtBearerTokenExample { public static String ...
2
votes
0answers
161 views

How to test getContent() calls in Spring '17?

Now that the Apex Mocks API and its Stub API complement are available is it possible to properly test for a getContent() call? In the past I would just branch out if unit test was running and returned ...
2
votes
0answers
79 views

Weird issue (NEW BUG) with Test.SetMock and body.toString() - Dreaded Uncommitted work pending

Using test.setMock between test.startTest and test.stopTest DML performs fine everywhere except: This code fails unless the insert is not done: sr = [Select Body From StaticResource Where Name = '...
2
votes
0answers
448 views

http mock for dom document

I am using http mock method for testing responses. But as one of the class expects DOM document and use response.getBodyDocument(). Usually, I used to insert sample response for http mock. I am ...
1
vote
0answers
29 views

'uncommitted work pending' callout exception thrown in *tests only*

I am converting a lead in the Execute method of a batch class, then making 2 callouts with those results in the Finish() method. It works gloriously and throws no errors. However, in the test ...
1
vote
1answer
382 views

Testing future callout method

I am attempting to test a @future callout class that pings another class to make an API call and update some fields in the Lead object. I am using the mock http method and here's the script: @isTest ...
1
vote
1answer
414 views

Visual Workflow plugin to callout to an external webservice and POST JSON

Can anyone help in providing an example of an APEX class which can make a HTTP JSON POST request to an external webservice using a plugin for SF visual workflow? Example I tried following here ...
1
vote
0answers
80 views

Hitting system limits with my testClass

I have two classes. One exposed as a REST service. Lets call this class "thefeeder". This class calls another class which implements Queueable interface. Lets call this class "theQueue". I wrote a ...
1
vote
0answers
1k views

System.TypeException: Methods defined as TestMethod do not support Web service callouts, test skipped

we have written trigger for echo-sign object, after updating object through our trigger, echo-sign code calls @future method from their managed package. this future method has webservice callout. Our ...
1
vote
1answer
284 views

HttpCalloutMock in test class fails only if insert an opportunity: You have uncommitted work pending. Please commit or rollback before calling out

Error: You have uncommitted work pending. Please commit or rollback before calling out. Problem: I have a callout request which works only if I don't inserting an opportunity before it in test class. ...
0
votes
0answers
22 views

Test.setMock working in Scratch org but not in sandbox Org

We have batch class used to make an API callout and doing Opportunity upsert DML operation in the Start method. Based on the opportunity's return value, we are making another API callout and doing ...
0
votes
2answers
75 views

mock test class and test class for 2 classes

I have 2 class A and B. A has code for Http Callout and from B we are calling A's class method which has callout code. So should we write mock test class for A only or do we have to write mock test ...
0
votes
1answer
45 views

Rest Callout Apex Test: How to Test @AuraEnabled Method?

guys! I have a problem with one method in my Apex class, which I need to cover by tests. This class uses "GET" callout and checks, if the input field is empty (null). If it is, the @AuraEnabled ...
0
votes
0answers
76 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 ...
0
votes
0answers
34 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 ...
0
votes
0answers
33 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
205 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. ...
0
votes
0answers
664 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. ...
0
votes
0answers
232 views

Test class code coverage for catch block in httprest api

below is my class code. code is not getting covered for the catch block. current code coverage is 75%. Also given below is my test class code. In need at least 90%. public class ...
0
votes
0answers
93 views

how to create test class with Rest Callouts using PageReference.getParameters().put method

I am using this method to fetch data : final PageReference link = new PageReference( 'https://login.salesforce.com/services/data/v37.0/tooling/query'); link.getParameters().put('q','select id from ...
0
votes
0answers
78 views

Error- Uncommitted Work Pending in test class. Trigger a future callout on record Update

I have trigger that makes a future callout when the record status changes to 'abc'. It working fine...End user updates the status to 'abc'. I am making a callout in method @future(callout=true). Now ...
0
votes
0answers
489 views

Error in batch test class with a mock

I write a test class for a batch that make a callout. So I wrote test class with a mock that I call in my batch test class. Here is the test class : @isTest private class y_batch_Test { @isTest ...
-2
votes
1answer
176 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 ...