I’m having a problem with MockK and JUnit5 in Andr...
# mockk
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
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
directory rather than
. I don’t know if that could be a problem.
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.
@streetsofboston I think you got it! I'll give that a try tomorrow.
👍 1
@streetsofboston Alas, I got the same error with:
Copy code
val activityInfo = mockk<ActivityInfo>(relaxed = true)
every { activityInfo.exported } returns exported
it could have to do with being in the
directory - maybe specify
on the class to get the robolectric test runner
also there are a lot of open issues for mockk related to android instrumented tests… could be one of those!