mmaillot
01/10/2019, 1:01 PMobject 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?raniejade
01/11/2019, 6:26 AMmemoized
.
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-conceptsmmaillot
01/11/2019, 9:25 AM