Hi there, I found a difference in behavior from 1....
# k2-adopters
s
Hi there, I found a difference in behavior from 1.9.21 to 2.0.0-Beta1. Maybe you guys could help me figure out if it's a bug or if I'm doing something I shouldn't be doing in the first place. I'm using JUnit4
@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.
Here's my sample:
Copy code
interface 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`:
Copy code
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:
Copy code
// <-- should be the rules here
at org.junit.runners.ParentRunner$3.evaluate(ParentRunner.java:306)