Questions tagged [apexmock]
The apexmock tag has no usage guidance.
49
questions
1
vote
1
answer
51
views
Apex Mocks - Verify that child is correctly related to a previously registered parent in Unit of Work
I have code where in the same Unit of Work I'm inserting a record and a related record, for example an Account and Contact.
Account acc = new Account(Name = 'Test acc');
unitOfWork.registerNew(acc);
...
1
vote
1
answer
178
views
How to I mock a void service that returns values in one of its arguments?
Let's say I have a typical fflib service class with a void method (Application.cls omitted for clarity)
public class MyService {
public static void doStuffInSitu(String someContext, MyWrapper ...
0
votes
1
answer
66
views
How to mock AuthSession in test class
I want to cover this method :
@AuraEnabled
public static void endUserSession(Id userId){
List<AuthSession> uSessions = [ select Id , UsersId FROM AuthSession WHERE UsersId =:userId AND ...
0
votes
0
answers
18
views
Hi I need to write the Mock Test class for my webservice test class, i am stuck , please help me to create the mock call out in the APEX [duplicate]
Below my class:
@AuraEnabled
public static ExtendedABRJsonResponse getExtendedABRDetails(String searchNumber, Boolean isABN) {
ExtendedABRJsonResponse theDefaultResponse = new ...
0
votes
0
answers
60
views
Partial mocking using ApexMocks Framework
I want to perform partial mocking using the Salesforce FFLib ApexMocks framework. For example, I have a class like the one below:
public class PropertiesServiceImpl implements IPropertiesService {
...
1
vote
1
answer
40
views
How to simulate (in test) record being deleted while callout is in progress
Let's say you have this pseudo code for some asynchronous transaction that processes an accountId
Account[] accounts = [SELECT Id, Name FROM Account WHERE Id = :accountId];
if (accounts.isEmpty) {...
1
vote
0
answers
45
views
Stub API not calling trigger
I am using Apex DML mocking using stub api and got a reference from multiple blogs,
https://github.com/packocz/Pragmatic-Bear-Blog
https://github.com/Coding-With-The-Force/Salesforce-Development-...
0
votes
1
answer
258
views
Can I mock out lookup relationship using FFLIB ApexMocks
I'm trying to mock out something similar to the following structure:
Task.LastModifiedBy.Username;
Task.LookupRelationshipToUser__r.Username;
Using the makeRelationships method for this doesn't make ...
2
votes
2
answers
217
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
526
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
135
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 ...
0
votes
1
answer
182
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(...
-2
votes
2
answers
385
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
698
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
1k
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 ...
0
votes
1
answer
931
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> ...
0
votes
2
answers
217
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....
1
vote
1
answer
585
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....
9
votes
2
answers
2k
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
98
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
322
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 ...
1
vote
1
answer
333
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:
...
0
votes
1
answer
230
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
800
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 ...
5
votes
1
answer
3k
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 ...
2
votes
1
answer
645
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; ...
2
votes
1
answer
306
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 ...
2
votes
1
answer
2k
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 ...
1
vote
1
answer
479
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(...
0
votes
1
answer
638
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....
8
votes
1
answer
4k
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
964
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 ...
2
votes
1
answer
2k
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+)....
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 ...
1
vote
1
answer
176
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 ...
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/...
3
votes
0
answers
414
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 ...
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.
2
votes
0
answers
4k
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 ...
0
votes
1
answer
801
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/...
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> ...
5
votes
1
answer
3k
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() ...
2
votes
1
answer
258
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: ...
3
votes
1
answer
3k
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
265
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 ...
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 ...
3
votes
1
answer
231
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
2k
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 ...
9
votes
1
answer
411
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 ...