Questions tagged [httpcalloutmock]

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

Filter by
Sorted by
Tagged with
13
votes
1answer
1k 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 ...
6
votes
2answers
1k views

Getting CalloutException when testing Batchable class with Callouts and HttpCalloutMock

I'm trying to write test code for a Batchable class that AllowsCallouts. I've written a lot of other test code that uses HttpCalloutMock classes, and planned to do so for this class as well. And, ...
17
votes
2answers
34k views

Method defined as testMethod do not support web service callouts, test skipped

I have been struggling with this error for a few days now. I get this error every time I try to run a test for a method that has an httpCallout. I followed the architecture from http://www.salesforce....
10
votes
3answers
660 views

Issue with Email Alerts and Test.setMock - Uncommitted Work Pending

Seeing this error now if an object has an email alert on it during insert and using test.setMock Disabling the workflow/process builder that contains the email alert and the test passes fine. Test....
15
votes
3answers
6k views

Challenge with unit tests, mock callouts and running as a user

Background I am developing a number of business applications within a community. Many of these apps rely on callouts to another ERP system to verify or retrieve or push data. In order to adequately ...
6
votes
3answers
3k views

Method does not exist or incorrect signature in Test.setMock

when i try to save the following code, i got the error below. Following same instructions given in this link, but still errors. Am i doing anything wrong here? please suggest. http://www.salesforce....
23
votes
4answers
6k views

Unit tests that need more than one WebServiceMock

I'm dealing with an odd situation where I need to call Webservice A to authenticate to Webservice B and Webservice C, all with different endpoints. I know how to setup mocks to test B and C ...
1
vote
2answers
936 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() { ...
17
votes
1answer
8k views

HttpCalloutMock Interface where there is more than 1 callout

Here is some background- I have an apex future method which is being called from an trigger. The future method then performs 3 different http calls to an external system (same endpoints). All requests ...
8
votes
3answers
7k views

how to test a future method which makes callouts?

I am practising the Integration workbook provided by salesforce. In tutorial#2 there's a class which makes future callouts to a Heroku app.This class is called by an after update trigger. Callout ...
8
votes
1answer
353 views

Unable to implement HTTPMock from Managed package in Local Test Methods - Complete example with package

A while ago SF began failing tests that make callouts without an HTTP mock. When they did that we were unable to deploy some trigger as a managed package made a callout whenever an Opportunity was ...
7
votes
1answer
4k views

You have uncommitted work pending. Please commit or rollback before calling out

I have written a callout class as below.But when a account is created/updated am getting the exception like "You have uncommitted work pending. Please commit or rollback before calling out" at 36 line(...
3
votes
1answer
15k views

Calling an external REST service in apex

I need to make a call to an external xml-rpc service in apex. I have written this little apex code: public static void callPBA() { HttpRequest req = new HttpRequest(); HttpResponse res = new ...
11
votes
2answers
1k views

“Callout loop not allowed” in unit test for Queueable that implements HttpCalloutMock

I'm attempting to do a unit test for a Queueable that does an Http callout. When I run the test I get an exception: "System.CalloutException: Callout loop not allowed". Previously I was using @...
7
votes
0answers
581 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 ...
5
votes
1answer
2k views

Mock Testing with Named Credentials

I've successfully implemented Named Credentials for a Basic Auth integration callout. However, when I went to write my test method, I noticed one minor annoyance. When I try to create a ...
2
votes
1answer
218 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 ...
1
vote
1answer
355 views

Test Class for HTTP Callout failing

This may sound repititve question. But the error incurs after following multiple links found like: here and here. The controller: public with sharing class SFLoginCtrlr { public static ...
-5
votes
1answer
1k views

Unable to Cover Future method which makes callout [closed]

Apex Class public with sharing class WarehouseCalloutService { private static final String WAREHOUSE_URL = 'https://th-superbadge-apex.herokuapp.com/equipment'; public static List<...
6
votes
1answer
4k views

how to get test coverage for @future and http response method in class

Below is my apex class and trigger, that is used to send sms from 3rd party application and that is working fine, but i'm not getting test coverage for class. If i use @future method my apex class ...
2
votes
1answer
2k views

Writing a test class for multi-callout method using MockHttpResponseGenerator

I have a future method which sends out two callouts. It looks something like this @future(callout = true) static webservice void SendCRMLeadFromTrigger(string leadID){ //FIRST CALLOUT ...
1
vote
2answers
736 views

Unit Testing Callout with Custom Setting

It appears that my Dev org's custom settings are not available within the scope of a unit test so I've written code to insert the needed custom setting within the test. I have a callout method which ...
1
vote
2answers
311 views

HTTP Mock Response class has 0 coverage

I have created a mock response to gain coverage for a hhtp request, as per the following documentation: https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/...