Questions tagged [apexmock]

The tag has no usage guidance.

Filter by
Sorted by
Tagged with
2
votes
1answer
34 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
125 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 ...
0
votes
1answer
54 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
35 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
47 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
257 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
156 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
168 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+)....
0
votes
1answer
561 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
79 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
730 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
136 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
808 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
2k 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
266 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
369 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> ...
2
votes
1answer
383 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
210 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: ...
2
votes
1answer
627 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
161 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
503 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
125 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
477 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
290 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 ...