New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error with Android Instrumented Tests Support #112

Closed
ricardorlg opened this Issue Jul 10, 2018 · 4 comments

Comments

4 participants
@ricardorlg

ricardorlg commented Jul 10, 2018

Prerequisites

  • [Yes ] I am running the latest version
  • [ Yes] I checked the documentation and found no answer
  • [ Yes] I checked to make sure that this issue has not already been filed

Expected Behavior

According to documentation, mockk can be used in Android Instrumented test, also It can mockk objects in Android P devices.

Current Behavior

Running tests that use mockkObject or mockk in an Emulator with Android P, I get the following error Missing calls inside every { ... } block

Failure Information (for bugs)

When a matcher is used in every block, I get io.mockk.MockKException: Failed matching mocking signature for left matchers: [more(2), more(5)] error

Context

  • MockK version: 1.8.5
  • OS: Windows - Android P and Android O
  • Kotlin version: 1.2.41
  • JDK version: 8
  • Type of test: unit test and android instrumented test

Stack trace

Stack trace with matchers

io.mockk.MockKException: Failed matching mocking signature for

left matchers: [more(2), more(5)]
at io.mockk.impl.recording.SignatureMatcherDetector.detect(SignatureMatcherDetector.kt:99)
at io.mockk.impl.recording.states.RecordingState.signMatchers(RecordingState.kt:38)
at io.mockk.impl.recording.states.RecordingState.round(RecordingState.kt:30)
at io.mockk.impl.recording.CommonCallRecorder.round(CommonCallRecorder.kt:45)
at io.mockk.impl.eval.RecordedBlockEvaluator.record(RecordedBlockEvaluator.kt:47)
at io.mockk.impl.eval.EveryBlockEvaluator.every(EveryBlockEvaluator.kt:25)
at io.mockk.MockKDsl.internalEvery(API.kt:93)
at io.mockk.MockKKt.every(MockK.kt:79).....

Stack trace without matchers

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)
at io.mockk.impl.eval.RecordedBlockEvaluator.record(RecordedBlockEvaluator.kt:48)
at io.mockk.impl.eval.EveryBlockEvaluator.every(EveryBlockEvaluator.kt:25)
at io.mockk.MockKDsl.internalEvery(API.kt:93)
at io.mockk.MockKKt.every(MockK.kt:79)....

Minimal reproducible code (the gist of this issue)

Example withouth matchers:

@RunWith(AndroidJUnit4::class)
class MockkIssueAndroidIntrumentedTest {
    object ObjectForMock {
        fun add(a:Int,b:Int)=a+b
    }
    class ClassForMock(){
        fun add(a:Int,b:Int)=a+b
    }
    @Test
    fun testForMockkObject() {


        mockkObject(ObjectForMock) // aplies mocking to an Object

        assertEquals(3, ObjectForMock.add(1, 2))

        every { ObjectForMock.add(1, 2) } returns 5

        assertEquals(5, ObjectForMock.add(1, 2))

        verifyAll {
            ObjectForMock.add(1, 2)
        }
    }

    @Test
    fun testForMock() {

        val mock = mockk<ClassForMock>()
        every { mock.add(1,2) } returns 5
        assertEquals(5, mock.add(1, 2))
        verifyAll {
            mock.add(1, 2)
        }
    }
}

Example with matchers:

@RunWith(AndroidJUnit4::class)
class MockkIssueAndroidIntrumentedTest {
    object ObjectForMock {
        fun add(a:Int,b:Int)=a+b
    }
    class ClassForMock(){
        fun add(a:Int,b:Int)=a+b
    }
    @Test
    fun testForMockkObject() {


        mockkObject(ObjectForMock) // aplies mocking to an Object

        assertEquals(3, ObjectForMock.add(1, 2))

        every { ObjectForMock.add(more(2), more(5)) } returns 10

        assertEquals(10, ObjectForMock.add(3, 6))

        verifyAll {
            ObjectForMock.add(3, 6)
        }
    }

    @Test
    fun testForMock() {

        val mock = mockk<ClassForMock>()
        every { mock.add(1,2) } returns 5
        assertEquals(5, mock.add(1, 2))
        verifyAll {
            mock.add(1, 2)
        }
    }
}

@oleksiyp oleksiyp added bug ait labels Jul 29, 2018

@oleksiyp

This comment has been minimized.

Show comment
Hide comment
@oleksiyp

oleksiyp Sep 30, 2018

Collaborator

This was a very stupid bug because this place was tagged with FIXME and it was just incorrect version check.

Please check version 1.8.9 or 1.8.9.kotlin13. Should be much better now. Sorry for the long lead time. My laptop was too slow to debug it. Now it is a lot better, so I can fix AIT bugs quite easy.

Collaborator

oleksiyp commented Sep 30, 2018

This was a very stupid bug because this place was tagged with FIXME and it was just incorrect version check.

Please check version 1.8.9 or 1.8.9.kotlin13. Should be much better now. Sorry for the long lead time. My laptop was too slow to debug it. Now it is a lot better, so I can fix AIT bugs quite easy.

@PLNech

This comment has been minimized.

Show comment
Hide comment
@PLNech

PLNech Oct 3, 2018

Is this issue still open? I see Fixed AIT for Android P+ v1.8.9 and v1.8.9.kotlin13 #112 on mockk.io 🤔

PLNech commented Oct 3, 2018

Is this issue still open? I see Fixed AIT for Android P+ v1.8.9 and v1.8.9.kotlin13 #112 on mockk.io 🤔

@oleksiyp

This comment has been minimized.

Show comment
Hide comment
@oleksiyp

oleksiyp Oct 3, 2018

Collaborator

It is still not confirmed that it is fixed on user side

Collaborator

oleksiyp commented Oct 3, 2018

It is still not confirmed that it is fixed on user side

@ImangazalievM

This comment has been minimized.

Show comment
Hide comment
@ImangazalievM

ImangazalievM Oct 11, 2018

@oleksiyp v1.8.9 works correctly with AIT. Thank you so much, good job!

ImangazalievM commented Oct 11, 2018

@oleksiyp v1.8.9 works correctly with AIT. Thank you so much, good job!

@oleksiyp oleksiyp closed this Oct 11, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment