[Koin 1.0] Testing improvements with declareMock() & declare()
See original GitHub issueHello,
koin-test
will no rely on mockito to provide out of the box mocking.
You can now directly declare a mock from a KoinTest
file with declareMock()
:
val mod = module {
single { ComponentA() }
single { ComponentB(get()) }
}
@Test
fun `successful override factory with a mock`() {
startKoin(listOf(mod))
// will override ComponentA with mock definition
declareMock<ComponentA>()
}
You can also declare some components with declare { }
, if you need more complex expression:
@Test
fun `successful override factory with a mock`() {
startKoin(listOf(mod))
// will override ComponentA with mock definition
declare { factory { DumbComponentA() } }
}
No need to declare a special module, if you have only local expressions/mocks.
Available in koin-test
version 1.0.0-beta-1
.
Issue Analytics
- State:
- Created 5 years ago
- Comments:9 (3 by maintainers)
Top Results From Across the Web
Injecting in Tests - Koin
by inject() & get() - function to retrieve your instances from Koin ... declareMock & declare - to declare a mock or a...
Read more >Mocking dependencies in UI test using Koin - ProAndroidDev
This is a simple way to mock runtime dependencies in Instrumentation tests when using Koin Library. First, let's take a look at how...
Read more >Five Reasons Why You Should Use Koin in Your Next Android ...
Here are 5 reasons why you should rely on Koin in your new Android ... testCompile 'org.koin:koin-test:1.0.1' ... declareMock<TasksContract.
Read more >CHANGELOG.md · Gitee 极速下载/koin - Gitee.com
Test. [ADDED] - asciidoc doc; [ADDED] - check() feature to check all configuration (does not create instances like dryRun); [ADDED] - declare mock...
Read more >How to mock a koin injected bean in android activity test and ...
This sample demonstrates how to use koin declareMock() in androidTest to capture then call lambda given as parameter of one mocked bean.
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Sample updated with declareMock. Now , I’m waiting for the release 😉
Thanks Arnaud, Now we have an nice way to do what we want I wrote a sample project using createMock that you can find here https://github.com/patrice-conil/testKoinMockBean Patrice