Skip to content
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
devluencer-089 opened this issue Oct 9, 2018 · 4 comments
Closed

Feature Request: clear recorded calls on all mocks #153

devluencer-089 opened this issue Oct 9, 2018 · 4 comments
Labels
enhancement fixed fixed in master

Comments

@devluencer-089
Copy link

devluencer-089 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() :-)

@devluencer-089
Copy link
Author

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
Copy link
Collaborator

oleksiyp commented Nov 3, 2018

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

oleksiyp added a commit that referenced this issue Nov 3, 2018
@oleksiyp oleksiyp added the fixed fixed in master label Nov 3, 2018
@oleksiyp
Copy link
Collaborator

oleksiyp commented Nov 3, 2018

Please verify the fix in version 1.8.11 or 1.8.11.kotlin13

@devluencer-089
Copy link
Author

It works.

Great work. Thanks for the new feature.

@oleksiyp oleksiyp closed this as completed Nov 3, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement fixed fixed in master
Projects
None yet
Development

No branches or pull requests

2 participants