https://kotlinlang.org logo
#mockk
Title
# mockk
p

poohbar

06/26/2020, 3:48 PM
is this answer still valid? https://stackoverflow.com/a/49819729
o

oleksiyp

06/26/2020, 4:16 PM
Yep, should work
p

poohbar

06/26/2020, 5:16 PM
Seems like
mockkStatic
is not thread safe? I run my tests in parallel and use
mockkStatic
of the same class in multiple different classes.
Since
mockkStatic
always unmocks the class first, if the other test is currently running it will briefly be able to access the unmocked class.
o

oleksiyp

06/26/2020, 5:26 PM
Yes, some of mockk parts weirdly behaving with parallel tests
p

poohbar

06/26/2020, 5:27 PM
trying this now:
Copy code
synchronized(UtilClass::class) {
    mockkStatic(UtilClass::class)
    every { UtilClass.staticMethod(any()) } returns 42
}
o

oleksiyp

06/26/2020, 5:31 PM
Might work :-)
You can just wrap only mockkStatic probably, not code setting beheviour
p

poohbar

06/26/2020, 5:32 PM
didn’t help unfortunately 😕
odd
o

oleksiyp

06/26/2020, 5:36 PM
Ah it wont
It is not possible to do actually
Coz state is flobal
Global
p

poohbar

06/26/2020, 5:37 PM
ok, i will have to find another way then, thank you
o

oleksiyp

06/26/2020, 5:37 PM
I.e. it is not possible to run parallel tests
Coz in the middle of one test state is being reset. You need to wrap whole tests then
2 Views