Maxr1998
12/04/2021, 8:54 PMbeforeAny
that filters TestType.Test
, I previously declared my DI mocks in beforeEach
so that I didn't have to do that extra check. However, with Kotest 5.0, beforeEach
gets called before beforeAny
in TestExtensions, which causes my mocks to fail because Koin hasn't started yet.
I wonder if the order in TestExtensions should be changed again, as I'd expect the outer scopes to evaluate before inner scopes, thus container → any → each.KoinLifecycleMode.Root
causes a NoSuchMethodException
.sam
12/04/2021, 9:00 PMMaxr1998
12/04/2021, 9:02 PMsam
12/04/2021, 9:03 PMMaxr1998
12/04/2021, 9:07 PMclass Sample : DslDrivenSpec(), StringSpecRootScope, KoinTest {
lateinit var mockedProperty: SessionRepository
init {
beforeEach {
mockedProperty = declareMock()
}
"Some test case" {
}
}
override fun extensions() = listOf(
KoinExtension(
modules = listOf(appModule, authModule),
mockProvider = { clazz -> mockkClass(clazz) },
),
)
}
sam
12/04/2021, 9:08 PMMaxr1998
12/04/2021, 9:10 PMStringSpec
normally.sam
12/04/2021, 9:10 PMMaxr1998
12/04/2021, 9:13 PMBut the trouble with trying to order beforeXX operations is that however you do it, someone somewhere will want it the other way.True, it was just a bit surprising that it changed after the upgrade. But I agree a more general solution would be preferable.
Probably moving the KoinExtension to be an interceptor will do the trick, then it will always run first.Is that something that I can do or does it have to be changed in the extension?
sam
12/04/2021, 9:15 PMMaxr1998
12/04/2021, 9:16 PMsam
12/04/2021, 11:33 PMMaxr1998
12/04/2021, 11:35 PMsam
12/04/2021, 11:35 PMMaxr1998
12/04/2021, 11:36 PMsam
12/04/2021, 11:37 PMMaxr1998
12/04/2021, 11:38 PMsam
12/04/2021, 11:40 PMMaxr1998
12/04/2021, 11:41 PMTest
in the second sample, thought it should maybe outline the root mode there.KoinTest
is just a simple marker to allow resolving Koin componentsKoinComponent
sam
12/04/2021, 11:44 PMMaxr1998
12/04/2021, 11:47 PMsam
12/04/2021, 11:53 PMMaxr1998
12/05/2021, 6:22 PMsam
12/05/2021, 6:22 PMMaxr1998
12/05/2021, 6:23 PMsam
12/05/2021, 6:29 PMMaxr1998
12/05/2021, 6:33 PMsam
12/05/2021, 6:34 PMMaxr1998
12/05/2021, 6:37 PMsam
12/05/2021, 6:41 PM