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

kluck

06/05/2019, 9:03 AM
Hi, I'm trying to use
verify(exactly = 1)
inside a kotlintest
BehaviorSpec
, but it fails as it doesn't seem to be isolated from my other
Given
scope. Here's a basic example:
Copy code
Given("foo") {
  every { persistentSource.getAccessToken() } returns IO.raiseError(exception)
  When("") {
    [...] Then [...]
  }
}
Given("foo2") {
  every { persistentSource.getAccessToken() } returns IO { smartphonePersistedAccessToken }
  When("") {
    [...]
    Then("") {
      verify(exactly = 1) { persistentSource.getAccessToken() }
    }
  }
}
l

LeoColman

06/05/2019, 4:29 PM
Pinging here from #kotlintest
What you're facing is exactly what you described. The mocks aren't being cleared between tests
What you need to do is either clear them on `afterTest`/`beforeTest or change the isolation mode so that the class is created more than once
To reset the mocks, I think you can use
clearMockks
or similar from #mockk itself
k

kluck

06/06/2019, 6:37 AM
I'll check this out, thanks!
16 Views