Currently the ApexMocks framework supports the following:
- verify a method was called with the correct arguments
- verify a method was called n number of times
- verify a method was never called
- stub a method call with a particular set of arguments to return a particular value
- stub a method call with a particular set of arguments to throw a particular exception
Caveats (given I developed ApexMocks in my free time):
- somewhat stating the obvious, I haven’t tested ApexMocks with every possible variant of method you could write in Apex
- apex-mocks-generator has not been tested against all possible variations of interface method definitions – it is possible it may fail when generating a mock class for some methods – if that happens please contact me. (Or if you are very brave edit the generated mock code directly.)
Please contact me @comic96 on Twitter or via this blog to feedback or ask questions. Or fork the GitHub repo. Thank you!
Can we have some Apex code examples of the supported features please?
There are full examples of all supported features in the fflib_ApexMocksTest class – these are the unit tests for the framework itself – using fflib_MyList as a ‘dummy’ component we would like to mock/stub. These unit tests fully illustrate all supported features.
So I kind of thought the unit tests would speak for themselves, but I could create more code samples too if that would help.
Thanks Paul found those, they got me moving with some aspects.
Pingback: Counters in Apex Mocks verifications – XoNoX Force
Pingback: Verify call’s order in Apex unit tests – XoNoX Force
Pingback: Answering with Apex Mocks – XoNoX Force