gojuno / minimock

Powerful mock generation tool for Go programming language
MIT License
632 stars 38 forks source link

feat: add 'Optional' to all mocked methods: 0 or more calls is now allowed #95

Closed DenKoren closed 4 months ago

DenKoren commented 6 months ago

In some (quite rare, but anyway) test cases you cannot predict if the method will be called for particular instance of mocked interface. Say, you test the concurrency and plan to execute 100 tasks. You expect the test to have 50 of tasks to be done and 50 to be not even started. But you do not know which of tasks the executor will choose, to set that 'the mock here should be called' and 'the mock here should NOT be called'. This is just out of your control, but you still want to check the constraint, that there is 50/50 results division.

For that case, the restriction of '1 or more' on a mocked method makes impossible to implement such test using minimock-generated interface mock implementation.

The default behavior of minimock to require calls for mocked methods is OK, it is just good to have control over it.

DenKoren commented 4 months ago

@hexdigest , sorry for the long delay. Found a window in my tight work schedule to fix the PR. Now it works on per-method basis.

hexdigest commented 4 months ago

Hey @DenKoren,

Thanks for the PR! This should be available in v3.3.10