Mockk Missing calls inside every { … } block












0














I'm stuck trying to mock some stuff with mockk:



I have the following setup on gradle



root:
|-- App (just a sample app for the SDK)
|-- SDK (SDK we develop) << apply plugin: 'com.android.library'
|-- SDKimpl.kt
|-- Foo (wrapper around a .jar library) << apply plugin: 'com.android.library'
|-- Foo.kt


So I'm writing an androidTest for the SDK and trying to mock Foo.kt.
There's nothing unusual about Foo class, just direct class Foo(private val someParams) {



So using androidTestImplementation "io.mockk:mockk-android:1.8.13" the mock goes:



val mock: Foo = mockk()
// val mock: Foo = mockkClass(Foo::class) // also tried this
every { mock.getData() } returns listOf("1", "2", "3")


I'm always getting the following crash:



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:42)


Also tried just to gather information:




  • running inside JVM test folder. It gets mocked without issues, but I can't run my test as JVM

  • running androidTest inside Foo module. Got the same crash

  • using mockkClass(Foo::class). Got some crash

  • using annotation @MockK and MockKAnnotations.init(this). Got some crash.

  • added Log.d before every { line and inside getData() method and it seems the actual real method from the class is getting called during the mock setup. That seems super weird to me.


Any idea what's going wrong here?



edit:



as requested, full code. I'm current working on an isolated project to try to isolate the error, so Foo is just:



class Foo {

fun getData(): String {
Log.d(TAG, "invoked foo.getData()")
return "trolololo"
}

}


and then I have FooTest in androidTest:



class FooTest {

@Test
fun mock_foo() {
val foo = mockk<Foo>()
every { foo.getData() } returns "zero"
assertEquals("zero", foo.getData())
}

}









share|improve this question
























  • post your Foo.kt full code
    – sasikumar
    Nov 20 at 11:43










  • @sasikumar I'm working on a separate test project to try to isolate the error. So there's really nothing on Foo, edited the question. It's all there.
    – Budius
    Nov 20 at 11:49
















0














I'm stuck trying to mock some stuff with mockk:



I have the following setup on gradle



root:
|-- App (just a sample app for the SDK)
|-- SDK (SDK we develop) << apply plugin: 'com.android.library'
|-- SDKimpl.kt
|-- Foo (wrapper around a .jar library) << apply plugin: 'com.android.library'
|-- Foo.kt


So I'm writing an androidTest for the SDK and trying to mock Foo.kt.
There's nothing unusual about Foo class, just direct class Foo(private val someParams) {



So using androidTestImplementation "io.mockk:mockk-android:1.8.13" the mock goes:



val mock: Foo = mockk()
// val mock: Foo = mockkClass(Foo::class) // also tried this
every { mock.getData() } returns listOf("1", "2", "3")


I'm always getting the following crash:



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:42)


Also tried just to gather information:




  • running inside JVM test folder. It gets mocked without issues, but I can't run my test as JVM

  • running androidTest inside Foo module. Got the same crash

  • using mockkClass(Foo::class). Got some crash

  • using annotation @MockK and MockKAnnotations.init(this). Got some crash.

  • added Log.d before every { line and inside getData() method and it seems the actual real method from the class is getting called during the mock setup. That seems super weird to me.


Any idea what's going wrong here?



edit:



as requested, full code. I'm current working on an isolated project to try to isolate the error, so Foo is just:



class Foo {

fun getData(): String {
Log.d(TAG, "invoked foo.getData()")
return "trolololo"
}

}


and then I have FooTest in androidTest:



class FooTest {

@Test
fun mock_foo() {
val foo = mockk<Foo>()
every { foo.getData() } returns "zero"
assertEquals("zero", foo.getData())
}

}









share|improve this question
























  • post your Foo.kt full code
    – sasikumar
    Nov 20 at 11:43










  • @sasikumar I'm working on a separate test project to try to isolate the error. So there's really nothing on Foo, edited the question. It's all there.
    – Budius
    Nov 20 at 11:49














0












0








0







I'm stuck trying to mock some stuff with mockk:



I have the following setup on gradle



root:
|-- App (just a sample app for the SDK)
|-- SDK (SDK we develop) << apply plugin: 'com.android.library'
|-- SDKimpl.kt
|-- Foo (wrapper around a .jar library) << apply plugin: 'com.android.library'
|-- Foo.kt


So I'm writing an androidTest for the SDK and trying to mock Foo.kt.
There's nothing unusual about Foo class, just direct class Foo(private val someParams) {



So using androidTestImplementation "io.mockk:mockk-android:1.8.13" the mock goes:



val mock: Foo = mockk()
// val mock: Foo = mockkClass(Foo::class) // also tried this
every { mock.getData() } returns listOf("1", "2", "3")


I'm always getting the following crash:



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:42)


Also tried just to gather information:




  • running inside JVM test folder. It gets mocked without issues, but I can't run my test as JVM

  • running androidTest inside Foo module. Got the same crash

  • using mockkClass(Foo::class). Got some crash

  • using annotation @MockK and MockKAnnotations.init(this). Got some crash.

  • added Log.d before every { line and inside getData() method and it seems the actual real method from the class is getting called during the mock setup. That seems super weird to me.


Any idea what's going wrong here?



edit:



as requested, full code. I'm current working on an isolated project to try to isolate the error, so Foo is just:



class Foo {

fun getData(): String {
Log.d(TAG, "invoked foo.getData()")
return "trolololo"
}

}


and then I have FooTest in androidTest:



class FooTest {

@Test
fun mock_foo() {
val foo = mockk<Foo>()
every { foo.getData() } returns "zero"
assertEquals("zero", foo.getData())
}

}









share|improve this question















I'm stuck trying to mock some stuff with mockk:



I have the following setup on gradle



root:
|-- App (just a sample app for the SDK)
|-- SDK (SDK we develop) << apply plugin: 'com.android.library'
|-- SDKimpl.kt
|-- Foo (wrapper around a .jar library) << apply plugin: 'com.android.library'
|-- Foo.kt


So I'm writing an androidTest for the SDK and trying to mock Foo.kt.
There's nothing unusual about Foo class, just direct class Foo(private val someParams) {



So using androidTestImplementation "io.mockk:mockk-android:1.8.13" the mock goes:



val mock: Foo = mockk()
// val mock: Foo = mockkClass(Foo::class) // also tried this
every { mock.getData() } returns listOf("1", "2", "3")


I'm always getting the following crash:



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:42)


Also tried just to gather information:




  • running inside JVM test folder. It gets mocked without issues, but I can't run my test as JVM

  • running androidTest inside Foo module. Got the same crash

  • using mockkClass(Foo::class). Got some crash

  • using annotation @MockK and MockKAnnotations.init(this). Got some crash.

  • added Log.d before every { line and inside getData() method and it seems the actual real method from the class is getting called during the mock setup. That seems super weird to me.


Any idea what's going wrong here?



edit:



as requested, full code. I'm current working on an isolated project to try to isolate the error, so Foo is just:



class Foo {

fun getData(): String {
Log.d(TAG, "invoked foo.getData()")
return "trolololo"
}

}


and then I have FooTest in androidTest:



class FooTest {

@Test
fun mock_foo() {
val foo = mockk<Foo>()
every { foo.getData() } returns "zero"
assertEquals("zero", foo.getData())
}

}






android kotlin mocking mockk






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 20 at 11:48

























asked Nov 20 at 11:04









Budius

31.6k1273112




31.6k1273112












  • post your Foo.kt full code
    – sasikumar
    Nov 20 at 11:43










  • @sasikumar I'm working on a separate test project to try to isolate the error. So there's really nothing on Foo, edited the question. It's all there.
    – Budius
    Nov 20 at 11:49


















  • post your Foo.kt full code
    – sasikumar
    Nov 20 at 11:43










  • @sasikumar I'm working on a separate test project to try to isolate the error. So there's really nothing on Foo, edited the question. It's all there.
    – Budius
    Nov 20 at 11:49
















post your Foo.kt full code
– sasikumar
Nov 20 at 11:43




post your Foo.kt full code
– sasikumar
Nov 20 at 11:43












@sasikumar I'm working on a separate test project to try to isolate the error. So there's really nothing on Foo, edited the question. It's all there.
– Budius
Nov 20 at 11:49




@sasikumar I'm working on a separate test project to try to isolate the error. So there's really nothing on Foo, edited the question. It's all there.
– Budius
Nov 20 at 11:49

















active

oldest

votes











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53391611%2fmockk-missing-calls-inside-every-block%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown






























active

oldest

votes













active

oldest

votes









active

oldest

votes






active

oldest

votes
















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.





Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


Please pay close attention to the following guidance:


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53391611%2fmockk-missing-calls-inside-every-block%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Create new schema in PostgreSQL using DBeaver

Deepest pit of an array with Javascript: test on Codility

Costa Masnaga