Feature request: expose mock method called counter or reset it

Open
#944 3 comments 6 reactions 0 assignees View on GitHub

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

enhancement

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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from stretchr/testify

All issues in stretchr/testify

Similar issues

More Go issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.