Hey guys! I just started with kotest + mockk and i...
# kotest
a
Hey guys! I just started with kotest + mockk and instantly faced an issue: since all tests are declared within one big lambda passed to ctor (
StringSpec
), all the mocks I need are declared as local variables inside same lambda and not re-initialized for each test case (like in vanilla JUnit). Essentially it means that the 2nd test can see mock invocations from the 1st one, messing up all verifications. How can I avoid that?
l
You can avoid this by either resetting the tests in an
afterTest
of some sort or you can set the IsolationMode of your spec class to
InstancePerTest
, that way the class will be created for every test
w
Or
InstancePerLeaf
, which as I understand will recreate the mocks only once per each test block, and not for the intermediate ones, right?
l
InstancePerLeaf might work as well
a
Works like a charm, thanks!
It looks like
InstancePerLeaf
is a better choice to prevent unanticipated calls.