Getting started with JUnit Tests
Let’s test our Koin injected application
This tutorial lets you test a Kotlin application and use Koin inject and retrieve your components.
Get the code
Checkout the project directly on Github or download the zip file
First, add the Koin dependency like below:
We reuse the
koin-core getting-started project, to use the koin module:
Writing our first Test
To make our first test, let’s write a simple Junit test file and extend it with
KoinTest. We will be able then, to use
by inject() operators.
For each test, we start startKoin() and close Koin context closeKoin().
You can even make Mocks directly into MyPresenter, or test MyRepository. Those components doesn’t have any link with Koin API.