-
-
Notifications
You must be signed in to change notification settings - Fork 719
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
merge inject and declareMock #243
Comments
Interesting proposal, thanks @dpreussler 👍 |
This feature is very interesting but a bit problematic because a lazy property won't be triggered at start. And if we want to predeclare mocks, we will have problems with overrides from the original and other stuff like that (because you predeclare a mock, and you load your original config). A first approach is to extend the declareMock like that: class CoffeeMakerTest : AutoCloseKoinTest() {
val coffeeMaker: CoffeeMaker by inject()
val heater: Heater by inject()
@Before
fun before() {
startKoin(listOf(coffeeAppModule))
declareMock<Heater> {
given(isHot()).will { true }
}
}
@After
fun after() {
stopKoin()
}
@Test
fun testHeaterIsTurnedOnAndThenOff() {
coffeeMaker.brew()
verify(heater, times(1)).on()
verify(heater, times(1)).off()
}
} |
We can't declare things in a lazy way, because nothing is triggered (like lazy of declareMock). This code has to be triggered manually then: declareMock<T>()
getKoin().get<T>(name, parameters).also {
KStubbing(it).stubbing(it)
} I fixed the original declareMock to find and override the original definition. Any idea else? |
understand but we still can pass the stubbing to declare mock right? |
@dpreussler yes |
1) Mockito Android 2.23.x is not compatible with current stable Android Gradle Plugin. Android Gradle Plugin 3.3.0-beta02 or higher is needed. See: mockito/mockito#1511 2) Koin 1.0.2 makes browser activity tests fail. It is probably an issue with the updated declareMock function. See: InsertKoinIO/koin#243
Is your feature request related to a problem? Please describe.
I don't like that declareMock is separate from the definition of the mock.
I normally try to do both in one call since Kotlin makes it so easy:
it' even better with Kotlin-Mockito:
Describe the solution you'd like
My idea would be sth similar to that approach.
This function combines the code from
inject
,delareMock
and the stubbingusage:
I believe this would look much nicer.
2nd part:
As we use Kotlin Mockito, as shown above, I would rather have a version for that.
Would look similar:
usage:
I understand you don't want to add Kotlin Mockito as a dependency. Maybe you have an idea how to combine both? Or in addition of the first version have one similar to on{} of Kotlin mockito. Its not complex, just needs to return
OngoingStubbing
from MockitoTarget Koin project
koin-test
The text was updated successfully, but these errors were encountered: