Feature request: expose mock method called counter or reset it
Nobody has claimed this yet.
Assessment
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Newbie friendliness
- 35/100
- Issue type
- Feature
- Clarity
- Mostly clear
- Activity status
- Stale
- Tech stack
- go
- Domain
- testing-qa
Research direction
Start with mock.Mock and its existing AssertCalled, AssertNumberOfCalls, and AssertNotCalled methods to understand how call history is tracked. Determine the intended behavior for exposing or resetting counts, then add focused tests showing that repeated test cases can verify both cache misses and cache hits without stale call history.
Written by the indexing model from the issue text.
Description
Senario:
Application implements some caching mechanism. I want to write test cases to test that if no cache exists, the mocked third-party service is called; if cached, the mocked service will not be called.
Feature request suggestion:
mock.Mock provides AssertCalled, AssertNumberOfCalls and AssertNotCalled methods, but if multiple test cases in one test suite calls the same mocking method,AssertNotCalled will fail no matter where the mocked method is called; number of calls is nearly impossible to know so AssertNumberOfCalls can not be used.
If mock.Mock can expose called times or allow reset call counter. On cache hit, AssertNotCalled can be used to check if mocking is not called, or using AssertNumberOfCalls to check if called counter does not increase.
- Dominant language
- Go
- Stars
- 26.2k
- Forks
- 1.9k
- Avg merge
- 2d 4h
- Merged PRs (30d)
- 2
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from stretchr/testify
-
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
-
bug
Difficulty 1/5 Under an hour Newbie friendliness 88/100
-
enhancement
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
-
internal/cleanup
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
All issues in stretchr/testify
Similar issues
-
optimization optimization:agents-md-curator
Difficulty 2/5 1-3 hours Newbie friendliness 86/100
githubnext/gh-aw-cao#13143 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 84/100
blinklabs-io/bursa#904 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 84/100
yanet-platform/ipfw-go#129 ·
-
bug confmap/provider/googlesecretmanagerprovider needs triage
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
open-telemetry/opentelemetry-collector-contrib#51273 · 2 comments ·
-
bug: AI Gateway client filter lists "Unknown" twice when NULL and literal Unknown clients coexist Openbug
Difficulty 2/5 1-3 hours Newbie friendliness 90/100