Yes, clear is suggested if you want to return back...
# mockk
o
Yes, clear is suggested if you want to return back default behavior, otherwise next mockkStatic will clear it
🙂 1
d
But if I add
clearMocks(SecurityContext.getAgentInfo())
to cleanup after each test I receive error
Copy code
io.mockk.MockKException: can't find stub [aid=AGENT_ID] [org=ORG_ID] [sid=null]

	at io.mockk.impl.stub.StubRepository.stubFor(StubRepository.kt:15)
	at io.mockk.impl.stub.CommonClearer.clear(CommonClearer.kt:16)
	at io.mockk.MockKKt.clearMocks(MockK.kt:654)
	at io.mockk.MockKKt.clearMocks$default(MockK.kt:227)
o
clearStaticMockk(SecurityContext::class)
But thats out of my heas
head
You can untranform class at all after test by unmockkAll
d
So the default behavior will be library's default?
o
But this may be more time consuming then clear
By default static mocks act like spies
So clear will just make all calls pass to original implementation
d
Thanks, will try
Should I after
clearStaticMockk
run
mockkStatic()
again?
For some reason I still get old value from mock...
o
Not really, but no harm, penalty
Ah maybe it is
clearMockkStatic
There is deorecated set of methoda there. I do not remeber it out of my head
Anyway if it is failing please report github issue
And meanwhile use unmockkStatic or unmockkAll
d
Ok, thank you. will create small repro case.
@oleksiyp I debugged code little bit. Could static function return null?
o
Should be possible AFAIK
d
While debugging when I'm in StubbingAwaitingAnswerState.kt in answer function
for ((idx, recordedCall) in calls.withIndex()) {
throws ConcurrentModificationException. Do you know who concurrently may change it? I'm still trying to make small repro for this, but when I'm not debugging this repro everything works fine. It looks like there is some multithread issue, but I can't understand why because I think that everything is running in one thread
When I go inside StubbingAwaitingAnswerState.kt I see the following exception inside calls property:
RecordedCall(retValue=<error "io.mockk.MockKException: Bad recording sequence. Please finalize every { ... } block with returns/answers/just Runs">, retType=Info, isRetValueMock=true matcher=class staticmockk.SecurityContext.getInfo()))
It happens when I go inside returns block in debug mode.
o
Debug may be tricky
As debugger calls toString
d
Yes... Unfortunately. Sometimes I have empty calls list, sometimes it has one elemnt and when I go inside the loop it the
lastCall
is false and debugger shows size = 0
In my main project I saw that mockk puts null as answer and while debugging static method returns not-null value for the call from previous test run even if I have
mockkStatic
function in each test.
@oleksiyp I'm sorry, it looks like I was wrong and mockk works perfectly! I fonud some issues in my tests
o
no issues, fill free to report anything. I anyway checking in detail it a lot later
265 Views