stretchr / testify

A toolkit with common assertions and mocks that plays nicely with the standard library
MIT License
22.5k stars 1.56k forks source link

mock: add assertion for minimum number of method/function invocations #1595

Open shalinlk opened 2 months ago

shalinlk commented 2 months ago

Summary

Method for asserting minimum number of invocations made to a method.

Changes

Added assertion method named AssertMinNumberOfCalls which takes expected minimum number of calls along with the method name for assertion. Assertion fails if specified minimum number of invocations are not made to the method.

Motivation

There are cases where exact number of invocations of a method cannot be predetermined accurately. Eg, number of network calls made by a retry logic which is governed by time out and time delay. Number of calls made in such cases will depend on time of previous call and time out of governing context. Hence ability to ensure a minimum threshold is required

Example usage

mockClient.AssertMinNumberOfCalls(t, "ModifyRule", 6)