Hi, I have this test: ``` object SplashScreenPrese...
# spek
m
Hi, I have this test:
Copy code
object SplashScreenPresenterTest: Spek({
    describe("SplashScreen presenter") {

        lateinit var viewMock: SplashScreenView

        describe("on no migration running") {

            val loadApplicationStateMock = mock<LoadApplicationState> {
                onBlocking { invoke(any()) } doReturn ApplicationState.MIGRATION_CLASSIC
            }
            val splashScreenPresenter = SplashScreenPresenter(viewMock, loadApplicationStateMock)
            it("should route to standard welcome screen") {
                runBlocking {
                    splashScreenPresenter.loadState()
                    verify(viewMock, times(1)).moveToClassicMigrationScreen()
                }
            }
        }
}
I want to use viewMock in multiple describe. I use verify, so I need to reset the mock for each describe. How can I init my viewMock for each describe?
r
You could use
memoized
.
Copy code
val viewMock by memoized { mock<>() }
Do note that, by default each test scope (`it`s) will have receive a unique value. You can pass in a
CachingMode
to
memoized
to control this behaviour. Other options are
CachingMode.GROUP
and
CachingMode.SCOPE
. I would also suggest reading this section of the docs: https://spekframework.org/core-concepts
m
Perfect, thank you! 🙂