Questions tagged [mock]

Mock classes are used in testing to simulate the responses of real code in a controlled, reproducible fashion. In particular, HTTPCalloutMock and WebServiceMock classes are used to supply response values to callouts made during a unit test.

Filter by
Sorted by
Tagged with
2 votes
0 answers

Post callout behavior assertions for unit test with static resource callout mock fail

I have a working queueable callout, and working tests using static resource callout mock I can successfuly run basic assertions on the mock response body and status. However, the callout method in ...
gorav's user avatar
  • 4,485
1 vote
2 answers

HttpRequest and HttpResponse is not covering in test class

I wrote a Testclass(Mock response) by implementing HttpCalloutMock interface to cover HttpRequest in class, I given some fake values to it also. But while calling the class, its not covering in ...
KS Kumaar's user avatar
  • 753
1 vote
1 answer

Problems with callouts Mock and tests

We have a problem in our organization and I was hoping for some advice from you on how to best tackle this. We have a handler class that makes a callout to a Master Data Management system for account ...
Ivar Gunnarsson's user avatar
4 votes
1 answer

test.setMock issue passing a parameter

I'm having difficulty passing a paramater to a HttpCalloutMock class. I have a trigger that calls a future callout on insert and on the response I'm receiving the record id so I can do the relevant ...
JPG's user avatar
  • 198
0 votes
1 answer

Rest Test class failing in production

I have the following Rest class and test class. The test class is working good in sandbox and failed in production. I have gone through numerous post and also followed to test with Mockclass as well. ...
user28452's user avatar
  • 431
1 vote
3 answers

Mock Service .setBody()

I am super stuck on my test coverage. I built a generic mock test class so I can reuse it. I typically just plug in the status code, status string, and body to be returned. I have used this mock class ...
Olivia's user avatar
  • 3,429
9 votes
2 answers

Is there a way I can mock an AggregateResult?

I'm trying to write most of my tests without hitting salesforce database. For that I'm implementing some simple mock class where I just return some SOQL queries when needed. The problem I'm facing now ...
Francisco Riccomagno's user avatar
2 votes
1 answer

Webservice mock callout goes to the webservice original class and fails

I am using a WebService callout, returning a string, and testing it; I am quite new to it. The problem is in the Mock class. When I am debugging it, the response element is created, the string is ...
Franktrt's user avatar
  • 173
0 votes
1 answer

ApexMocks: setMock() not working

I'm trying to unit test a very simple Account service but for some reason it appears the setMock() is not working. I'm using the following unit test example as a guide and I'm pretty positive I ...
Xtremefaith's user avatar
  • 4,520
3 votes
1 answer

ApexMock FileNotFound Exception

I am trying to learn how to write tests for apex services using ApexMocks framework. I want to generate Mock classes through apex-mocks-generator and I am following simple instructions given in this ...
Faiza Iqbal's user avatar
1 vote
1 answer

Mock class not working with Dynamic & Unique end-point

i am fetching some remote data into my salesforce and i am using "oauth_signature" in my end-Point URL for remote web services so my API URL is unique for every API request. my all functionality is ...
Rajinder's user avatar
  • 119
0 votes
1 answer

How to write test class for http callouts?

Hi I am writing test class for callouts class any one help on this. This is my code: public class recoverrecords{ public static string response; public static list<string> first = new List<...
user321's user avatar
  • 87
9 votes
1 answer

ApexMocks - Assertion Fails

I am hoping for some help in figuring out why some mocking is not working. I am currently using ApexMocks and the FinancialForce Apex Common Library and knowledge of those would be necessary to help ...
techbusinessman's user avatar
1 vote
1 answer

You have uncommitted work pending. Please commit or rollback after [sic] calling out

Below class gives error "You have uncommitted work pending. Please commit or rollback after calling out". //Call out from batch public void execute(Database.BatchableContext bc, List<...
sf_user's user avatar
  • 2,208