apex-enterprise-patterns / fflib-apex-mocks

An Apex mocking framework for true unit testing in Salesforce, with Stub API support
BSD 3-Clause "New" or "Revised" License
423 stars 214 forks source link

How to verify a Method was called N times? #124

Closed AllanOricil closed 3 years ago

AllanOricil commented 3 years ago

I have this exception on methods that I call twice

fflib_ApexMocks.ApexMocksException: Expected : 1, Actual: 2

but I don't know how to set the number of times I expect the method to be called

ImJohnMDaniel commented 3 years ago

@AllanOricil regarding some of these Apex Mocks questions, there is an "Apex Mocks Reading List" that I have curated over the years and just posted to the project wiki. I believe it will be helpful.

The ApexMocks Reading List

ImJohnMDaniel commented 3 years ago

Specifically, the articles by Vincenzo Denti might be helpful

AllanOricil commented 3 years ago

@ImJohnMDaniel thanks john. I figured it out reading the code

If anyone needs help with it,

just pass a number as a second argument to verify, like

((DSP_IDocumentSigningRequests) mocks.verify(documentSigningRequestsMock, 2)).getRecordsMap();