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: Attempt to de-reference a null object

Anyone with experience with the ApexMocks framework that can tell me why the test is failing?

Class to test:

public class fflib_MyList implements IList {
    List<String> myList;

    public fflib_MyList() {
        this(new List<String>());

    private fflib_MyList(List<String> myList) {
        this.myList = myList;

    public void add(String value) {

    public String get(Integer index) {
        return myList.get(index);

    public void clear() {

    public Boolean isEmpty() {
        return myList.isEmpty();

    public interface IList {
        void add(String value);
        String get(Integer index);
        void clear();
        Boolean isEmpty();

ApexMocks test:

private class MockTest {
    static testMethod void testBehavior() {
        // Given
        fflib_ApexMocks mocks = new fflib_ApexMocks();
        fflib_MyList.IList mockList = (fflib_MyList.IList)mocks.mock(fflib_MyList.class);

        // When

        // Then
        ((fflib_MyList.IList) mocks.verify(mockList)).add('bob');
        ((fflib_MyList.IList) mocks.verify(mockList, fflib_ApexMocks.NEVER)).clear();

Source : FinancialForce ApexMocks Framework


I've seen reports recently that Test.createStub() started returning null. Assuming the ApexMocks framework uses that method, which it almost certainly does, then that could explain the null pointer exceptions.

Any1 having issues executing Test.createStub(Type,Object) today? Started seeing it return null an hour ago #askforce @SalesforceDevs


Related Github Issue - fflib_InvocationOnMock is failing

Related Known Issue - System.Test.CreateStub method returns NULL in Apex Tests

| improve this answer | |
  • ApexMocks framework uses Stub API :( – Cuban coffee Aug 8 '17 at 20:27
  • 1
    On the plus side, from the Known Issue it sounds like the patch is already mostly deployed. – Daniel Ballinger Aug 8 '17 at 20:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.