Questions tagged [apexmock]

The tag has no usage guidance.

Filter by
Sorted by
Tagged with
2 votes
0 answers
76 views

ApexMocks and UoW implementing IDoWork interface

I have extended the main functionality of the fflib_ISObjectUnitOfWork to enable upserts considering External Ids. Basically, I have created a new class implementing the fflib_SObjectUnitOfWork....
2 votes
1 answer
108 views

fflib_ApexMocks is not returning the expected value

I am using fflib_ApexMocks without any issue till today. However, for this case, I am not able to understand what I am doing wrongly. This is the magical mock: mocks.when(appointmentServiceMock....
1 vote
1 answer
62 views

How to verify non-deterministic field values in a unit test that does no DML?

for fflib / apexmocks users Let's say you have a class/method that inserts new objects where a field value is non-deterministic, say, a UUID public class AccountsServiceImpl { public void ...
  • 63.7k
0 votes
1 answer
76 views

BASHFUL error running testmethod using ApexMocks (StubApi)

Given fflib code that looks like for (Contact c: contacts) { uow.registerEmail(someEmailMessage); } With testmethod ApexMocks verify (which uses StubApi) ((fflib_SObjectUnitOfWork)mocks.verify(...
  • 63.7k
-2 votes
2 answers
121 views

Apex Mock Domain Factory Error

Running into an issue with Implementing Apex Mocking. Everything works fine until I try to set the domain mock in the domain class. Here is My Code: @IsTest private static void testMocking(){ ...
2 votes
1 answer
307 views

Any option for mocking custom metadata records using fflib-ApexMocks and fflib-apex-common?

Given a project based on fflib-apex-common and using fflib-ApexMocks for unit testing, I would like to mock Custom Metadata records and stop using real org values. Custom metadata queries are ...
1 vote
1 answer
363 views

Apex Mocks avoiding insert when committing fflib Unit of Work

I'm new in Apex Mocks but I'm really excited about all it's advantages. I'm trying to build test without DML. Here is a method I'm trying to test at the moment: public Id createMmDocument(String ...
  • 15
0 votes
1 answer
285 views

Testing service methods which fflib unit of work in method's signature

So what I'm tying to do is to unit test one of methods in my service: @TestVisible private void insertSerialNumbers(List<AST_Material_Document_Item__c> documentItems, Map<Id, Asset> ...
  • 15
0 votes
2 answers
113 views

How to test Job states for a Apex Test with CronTrigger being read only?

I have the following function in a class that implements System.Schedulable: @TestVisible private void rescheduleJob(CronTrigger me, ISchedulable item, MySchedulableContext myCtx) { if (me....
  • 481
1 vote
1 answer
338 views

Apex Mocks test error for Domain class

We have been using FFLIB(Apex commons) in our org.I have been trying to write a test case for a Content Document Link (Salesforce Files)Domain layer But i have been getting the error : "System....
8 votes
2 answers
1k views

Mocking Database.QueryLocator in Unit Tests using fflib Apex Mocks

Assume we have some basic AccountSelector class that has different implementations of the selector method. QueryLocator variation is helpful once we need to take advantage of SOQL for loops or to use ...
0 votes
1 answer
57 views

Apex Mocks github deployment to Production stuck in Status: Queued

I'm attracted to the FinancialForce apexmocks and related libraries, and have successfully deployed to Trailhead playgrounds, Dev sandboxes and our full sandboxes. The deployments ran quite smoothly ...
3 votes
1 answer
208 views

Stubbing Logger classes with methods accepting Exceptions

I recently needed to write a test that checks if an exception gets logged. We have a Logger but it's built with static methods, so it cannot be stubbed. But I didn't want to test the Logger logic, so ...
  • 961
1 vote
1 answer
215 views

ApexMocks - Not able to verify Insert of a sObject record

I'm trying to write unit test (using fflib framework) for a piece of functionality where on insertion of an object files are created. This is the main piece of code i'm trying to cover: ...
  • 525
0 votes
1 answer
155 views

fflib-apexmock not getting verified

I am using fflib mocks and at4dx Trying to test a simple controller method which is calling a selector method. Controller Method: public with sharing class MyController { public static String ...
2 votes
1 answer
610 views

System.JSONException while using the SObjectFabricator library [closed]

I am using the SObjectFabricator library (https://github.com/mattaddy/SObjectFabricator) in order to fabricate/create an object with relationships for mocking purposes. I have two Sobjects ...
  • 481
5 votes
1 answer
2k views

Why are my matchers not working after adding an overloaded method?

To help getting past our permission checks during unit tests to test actual functionality, I created a mocking class so people could just call the mocking method they needed from that class for the ...
  • 73
2 votes
1 answer
301 views

mocking method with any instance, string and enum

I am trying to mock a class with a method that has 3 arguments, and these 3 arguments could be any of its own types. I used the fflib_ApexMocks to return 'hello world' whenever the method is called; ...
  • 1,458
2 votes
1 answer
262 views

Where or how can I find what interfaces an out of the box Apex class implements?

Is there a method of discovering (or a place to look up) all of the interfaces that an out of the box Salesforce class (Like LoginHistory) implements? The reason I ask: I'm attempting to test a ...
  • 765
1 vote
1 answer
1k views

ApexMocks - throw exception on 1st call but not on second

Given Some class MyCode that calls a void method in MyService.doStuff(SObjectType sobjType) You plan on stubbing MyService.doStuff(...) to make unit testing of MyCode easier, faster, and more ...
  • 63.7k
1 vote
1 answer
355 views

Can I have multiple ApexMocks startStubbing()-stopStubbing() Pairs in same testmethod?

All the examples, e.g. for ApexMocks use a single wrapper: mocks.startStubbing(); ... your stub returns here mocks.stopStubbing(); But what happens if your testmethod involves multiple startStubbing(...
  • 63.7k
0 votes
1 answer
369 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....
7 votes
1 answer
3k views

My ApexMocks aren't working - what could be wrong?

Canonical Question and Answer When using ApexMocks, I'm getting unexpected results. What could be the possible reasons? Here are some of the symptoms I observe: Null pointer exception in my service ...
1 vote
1 answer
718 views

How to mock a private property in controller correctly?

I have a controller with a private property that holds an instance of an object. The code below is reduced from unnecessary details. public with sharing class BarController { private Foo ...
  • 4,767
1 vote
1 answer
808 views

Using Parallel Test annotation for Apex mocking framework

Currently in my org there are around 50 test class which just uses Apex mocking framework and has no interaction with database. I have other test classes that is actual Apex test classes(around 1000+)....
  • 4,591
1 vote
1 answer
2k views

Can we mock relationships in Apex?

I have a custom object called Document__c that looks up to Account. Account has a lookup field to another custom object called Business__c. In SOQL, the following query will return the id of ...
  • 2,172
1 vote
1 answer
139 views

Adding open-source libraries to a managed package

We want to be able to level-up our testing and have found ApexMocks as a very helpful library that we can use for this purpose. I'm not sure if I can cover ALL the use cases but I hope it can help us ...
  • 2,172
9 votes
2 answers
2k views

Testing with ApexMocks vs Stub API

We are looking into using ApexMocks to improve the tests in our managed package. The problem is that it looks like we will need to bring it into our package which will increase the number of classes/...
  • 2,172
3 votes
0 answers
324 views

Mock a class that implements Schedulable using Stub API

I'm using Stub API (https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_testing_stub_api.htm) to mock a class that implements Schedulable and because of this I'm getting an ...
  • 305
5 votes
1 answer
2k views

Unit Test Big Objects

I have an APEX controller that writes to a Big Object. How do I unit this? During an insert operation insert I get an error: Unsupported External Object Operations.
  • 315
2 votes
0 answers
3k views

ApexMock - Test method to invoke a Queueable method fails

I am using ApexMocks to write unit tests for a method that invokes a Queueable class. My test objective is to verify is the class has been invoked once via the trigger handler. Below is a sample code ...
  • 4,591
0 votes
1 answer
621 views

Using ApexMocks for a class that implements Queueable Interface

I am trying to write a unit test for a trigger handler method that enqueues a queueable class. I am using ApexMocks to write the unit test for this trigger method. https://github.com/financialforcedev/...
  • 4,591
2 votes
1 answer
2k views

ApexMocks from FFlib not getting verified at run time

Trying to test a simple overloaded service. AccountsService.cls public static List<Account> getAccounts(Set<Id> ids){ /* This selector needs to be mocked */ List<Account> ...
  • 4,398
4 votes
1 answer
2k views

ApexMocks - Verifying Sobject updates (fflib Unit of Work)

(Been spending quite a bit of time learning ApexMocks in conjunction with fflib pattern). Example simplified from more involved code Class/method under test public class Foo { public void doWork() ...
  • 63.7k
2 votes
1 answer
255 views

MocksApex - behaviour verification

I am using the ApexMocks framework and I am having the following error message: Class.MockTest.testBehavior: line 13, column 1 11:53:56.3 (10709808)|FATAL_ERROR|System.NullPointerException: ...
  • 1,458
3 votes
1 answer
2k views

fflib_ApexMock: How to mock static methods?

Static methods are called without creating instance of a class. The fflib_ApexMock library gives option to mock, but how to call static methods when mocking a class. Like in Mockito we have ...
2 votes
0 answers
211 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 ...
  • 3,816
0 votes
1 answer
1k views

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 ...
  • 4,398
3 votes
1 answer
203 views

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 ...
4 votes
3 answers
1k views

How to unit test service layer without DML

Looking for best practices/suggestions on how to unit test a service layer method that creates new records based on input without having to issue the DML. An example would be ...
  • 101
9 votes
1 answer
391 views

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 ...