New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature Request: clear recorded calls on all mocks #153

Closed
michaelom opened this Issue Oct 9, 2018 · 4 comments

Comments

2 participants
@michaelom

michaelom commented Oct 9, 2018

  • [x ] I am running the latest version
  • [x ] I checked the documentation and found no answer
  • [x ] I checked to make sure that this issue has not already been filed

The current API comes with a handy function to unstub all mocks: unmockkAll()
Unfortunately there is no way to clear recorded calls in a similar fashion.

clearMocks(...) requires the mock to be passed as an argument. When the mock object is not in scope (e.g. test lifecycle listener) there is currently no way to clear recorded calls.

I am aware this functionality is rarely required. So is unmockAll() :-)

@michaelom

This comment has been minimized.

michaelom commented Oct 9, 2018

Here is an example:

class MockResettingLifecycleListener : LifecycleListener {
    override fun afterExecuteGroup() {
         clearAllMocks()
     }
}

During test execution mocks reside in a (stateful) DI-Container. If not cleared after test execution, state gets carried over to the next test.

@oleksiyp

This comment has been minimized.

Collaborator

oleksiyp commented Nov 3, 2018

Finally I am doing some coding and going to take this one

@oleksiyp oleksiyp added the enhancement label Nov 3, 2018

oleksiyp added a commit that referenced this issue Nov 3, 2018

@oleksiyp oleksiyp added the fixed label Nov 3, 2018

@oleksiyp

This comment has been minimized.

Collaborator

oleksiyp commented Nov 3, 2018

Please verify the fix in version 1.8.11 or 1.8.11.kotlin13

@michaelom

This comment has been minimized.

michaelom commented Nov 3, 2018

It works.

Great work. Thanks for the new feature.

@oleksiyp oleksiyp closed this Nov 3, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment