mockk icon indicating copy to clipboard operation
mockk copied to clipboard

Suggestion: Recommendations for running parallel tests

Open sharmando opened this issue 3 years ago • 9 comments

I think it would be useful to add a section about running mock with parallel test execution.

I understand now that clearAllMocks is not compatible with parallel tests as it will clear mocks across tests but I was confused about the behavior for a couple of days.

I am using mockk<> coEvery and coVerify with no issues. But if some areas of mockk are not threadSafe or not recommended for parallel test execution that could also be discussed in the parallel execution section.

sharmando avatar Jul 24 '22 17:07 sharmando

mockkObject is also not threadsafe?

nilajasp avatar Aug 05 '22 09:08 nilajasp

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. If you are sure that this issue is important and should not be marked as stale just ask to put an important label.

stale[bot] avatar Nov 02 '22 02:11 stale[bot]

I'm interested in this as well. We want to have fast tests, so we need to run in parallel. We've been creating classes just to wrap functions for the sake of mocking. IMO, we should be using top level functions, but the inability to use mockkStatic in parallel is preventing us from doing so.

If there's a (future) paradigm where we can run these tests in parallel, I can convince my team on giving up parallel tests for now so we can use all the language features. Otherwise, we're having to give up functionality because of testing, which seems like a huge loss.

aiguofer avatar Mar 13 '23 22:03 aiguofer

Seems like others have also been experiencing related issues: #1062

aiguofer avatar Mar 13 '23 22:03 aiguofer

Probably mockkConstructor is affected as well. I was just investigating an issue with some flakyness when running tests in our CI environment when I noticed this issue. After disabling parallel execution, the test suite went back to green.

milgner avatar Apr 18 '23 10:04 milgner

Experiencing a similar issue with clearAllMocks, where my mocks are being cleared mid-execution of some other suites running in parallel. :(

tjshamhu avatar Apr 20 '23 14:04 tjshamhu

This is known and I guess just accepted behavior https://github.com/mockk/mockk/issues/301#issuecomment-492512079

Leads to some wicked bugs, when not expected.

Spirarel avatar Aug 03 '23 18:08 Spirarel

Should there not be a static mock scope, where we define the mock'ed static method/object/etc to only exist withtin a scope. Doing mockkObject and then unmock feels like a old way of doing things in the Kotlin reality of scopes/blocks/lambdas.

cies avatar Oct 27 '23 14:10 cies

Related issue: #764

cies avatar Oct 27 '23 14:10 cies