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?


1 Answer 1


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:


You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .