I’m having a problem with MockK and JUnit5 in Android development. Here is my code:
Copy code
private fun makeResolveInfo(appName: String, packageName: String, exported: Boolean = true) :
ResolveInfo {
val activityInfo = mockk<ActivityInfo>()
every { activityInfo.exported } returns exported
// remaining code omitted
The program crashes on the line with
every
:
Copy code
io.mockk.MockKException: Missing calls inside every { ... } block.
at io.mockk.impl.recording.states.StubbingState.checkMissingCalls(StubbingState.kt:14)
at io.mockk.impl.recording.states.StubbingState.recordingDone(StubbingState.kt:8)
at io.mockk.impl.recording.CommonCallRecorder.done(CommonCallRecorder.kt:47)
at io.mockk.impl.eval.RecordedBlockEvaluator.record(RecordedBlockEvaluator.kt:60)
at io.mockk.impl.eval.EveryBlockEvaluator.every(EveryBlockEvaluator.kt:30)
at io.mockk.MockKDsl.internalEvery(API.kt:92)
at io.mockk.MockKKt.every(MockK.kt:104)
at mozilla.voice.assistant.intents.MetadataTest$Companion.makeResolveInfo(MetadataTest.kt:61)
Any idea what I’m doing wrong? The file is in a
test
directory rather than
androidTest
. I don’t know if that could be a problem.
s
streetsofboston
03/25/2020, 2:44 AM
I could be mistaken, but it looks like you need a relaxed mock, since you may be not mocking all methods and properties of the ActivityInfo.
e
Ellen Spertus
03/25/2020, 2:45 AM
@streetsofboston I think you got it! I'll give that a try tomorrow.
👍 1
Ellen Spertus
03/25/2020, 6:04 PM
@streetsofboston Alas, I got the same error with:
Copy code
val activityInfo = mockk<ActivityInfo>(relaxed = true)
every { activityInfo.exported } returns exported