Questions tagged [apexmock]

The tag has no usage guidance.

Filter by
Sorted by
Tagged with
1
vote
0answers
33 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
0answers
38 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 ...
0
votes
1answer
33 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 ...
0
votes
0answers
43 views

Testcoverage for external Objects

It seems that Salesforce does not provide adequate tools to get a Testcoverage for external Objects. There are some Workarounds: Unit Testing External Object with Mocked Data Apex Test coverage on ...
5
votes
1answer
111 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
1answer
69 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
1answer
139 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 ...
1
vote
1answer
205 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
1answer
99 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
1answer
79 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....
5
votes
1answer
698 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 ...
0
votes
1answer
248 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 ...
1
vote
1answer
225 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
1answer
797 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
1answer
95 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 ...
8
votes
2answers
1k 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
0answers
191 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
1answer
1k 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
0answers
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 ...
0
votes
1answer
349 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
1answer
672 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> ...
3
votes
1answer
691 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
1answer
225 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
1answer
922 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
0answers
169 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
1answer
606 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
1answer
151 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
3answers
629 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
1answer
317 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 ...