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 powerMockito.mockStatic. How can we achieve same in apex mock?

For Eg: this gives NullPointerException:

apexMocks.when(AStaticClass.getPriceBookProducts('')).thenReturn(new Map<String>());

And if I try to mock the AStaticClass and used the reference it says cannot call static methods from initialized object. Which is obvious. Anybody tried to mock static class?


I was looking for the same solution, but it doesn't appear that FF plan to implement it as of now. Here is where it was reported as an issue on the repo and they replied saying they couldn't implement it due to limitations in Apex:


| improve this answer | |

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.