s3rius
12/20/2023, 5:25 PM@Rule
in my tests. I created an interface+implementation to encapsulate the rules and some utility functions. In 1.9.21 this works fine, in 2.0.0 Junit won't pick up the rules anymore if using interface.
Sample code is in reply.s3rius
12/20/2023, 5:26 PMinterface TestBase : KoinTest {
@get:Rule
val mockProviderRule: MockProviderRule
@get:Rule
val testRule: KoinTestRule
}
open class ActualTestBase : TestBase {
@get:Rule
override val mockProviderRule = MockProviderRule.create { mockkClass(it) }
@get:Rule
override val testRule = KoinTestRule.create()
}
class MockTest
// Implement via class inheritance
// Works in 1.9.21
// Works in 2.0.0-beta1
class Test1 : ActualTestBase() {
@Test
fun test() {
declareMock<MockTest> { } // just something to use the testRule
}
}
// Implement via interface and delegation.
// Works in 1.9.21
// Doesn't work in 2.0.0-beta1 ("Koin not started" exception due to TestRule not being executed)
class Test2 : TestBase by ActualTestBase() {
@Test
fun test() {
declareMock<MockTest> { } // just something to use the testRule
}
}
When looking at the stack inside the test functions I can see that the test rules show up in the stack (as expected) for `Test1::test`:
at org.koin.test.mock.MockProviderRule$apply$1.evaluate(MockProviderRule.kt:28)
at org.junit.rules.TestWatcher$1.evaluate(TestWatcher.java:61) // <- KoinTestRule
at org.junit.runners.ParentRunner$3.evaluate(ParentRunner.java:306)
But inspecting the same part of Test2::test
yields nothing:
// <-- should be the rules here
at org.junit.runners.ParentRunner$3.evaluate(ParentRunner.java:306)