io.mockk.MockKException: Bad recording sequence. Please finalize every { ... } block with returns/answers/just Runs

See original GitHub issue
  • MockK version: 1.8.13
  • OS: Android
  • Kotlin version: 1.3.10
  • JDK version: 1.8
  • JUnit version: 5
  • Type of test: unit test OR android instrumented test

Stack trace

io.mockk.MockKException: Bad recording sequence. Please finalize every { ... } block with returns/answers/just Runs
class NoPermissionsPresenterTest : RxSpek({
    val view = mockk<NoPermissionsContract.View> {
        every { onVisibilityChangeObservable } returns Observable.just(true)
    }
    val navigator = mockk<NoPermissionsContract.Navigator> {
        every { back() } returns Unit
    }

    val rxPermissions = mockk<RxPermissions> {
        every { isGranted(any()) } returns true
    }
    val presenter by memoized(CachingMode.GROUP) {
        NoPermissionsPresenter(
            rxPermissions = rxPermissions,
            navigator = navigator
        )
    }

    describe("NoPermissionsPresenter tests") {
        describe("view observables") {
            beforeGroup {
                presenter.attachView(view)
            }
            on("visibility change to true") {
               view.onVisibilityChangeObservable.test()
                it("check permissions") {
                    verify { rxPermissions.isGranted("") }
                }
                it("navigates back") {
                    verify { navigator.back() }
                }
            }
        }
    }
})

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:5

github_iconTop GitHub Comments

3reactions
patrickcousinscommented, Feb 11, 2019

Just in case someone stumbles on this, in my case it was having trouble with the answer being an expression/function.

every { mockObj.func() } returns someObject.fakeAnswer()

But this worked:

val fakeAnswer = someAnswerObject.funcAnswer()
every { mockObj.func()} returns fakeAnswer
2reactions
oleksiypcommented, Nov 19, 2018

Hey, can I ask what was the problem?

Read more comments on GitHub >

github_iconTop Results From Across the Web

io.mockk.impl.recording.states.CallRecordingState.kt Maven ...
Please finalize every { ... } block with returns/answers/just Runs") } else { throw MockKException("Bad recording sequence. State: ${state::class.
Read more >
Yes clear is suggested if you want to return back default be
RecordedCall(retValue=<error "io.mockk.MockKException: Bad recording sequence. Please finalize every { ... } block with returns/answers/just Runs">, ...
Read more >
mockk-io/Lobby - Gitter
What's this error: io.mockk.MockKException: Bad recording sequence. State: StubbingState Just refresh the project, then some passing tests become failed xD.
Read more >
How do you Mockk a Kotlin top level function? - Stack Overflow
Could the problem be that the top level function I'm trying to mock has a varargs parameter, but I'm doing every { sayHello(any(),...
Read more >
Many tests suddenly fail with Spek 2.0.13 - Giters
Thanks for the report @svenjacobs. Are you able to provide a reproducer? My guess is that mockk doesn't play well with coroutines.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found