I’m having a problem with MockK and JUnit5 in Andr...
# mockk
e
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
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
@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
m
it could have to do with being in the
test
directory - maybe specify
@RunWith(AndroidJUnit4::class)
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!