From 51541fa00e4e68e374b9c0d4fafc198323078d6e Mon Sep 17 00:00:00 2001 From: Igor Wojda Date: Fri, 5 Jul 2024 15:12:05 +0200 Subject: [PATCH 1/2] Add testing description for Context Isolation --- docs/reference/koin-core/context-isolation.md | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/docs/reference/koin-core/context-isolation.md b/docs/reference/koin-core/context-isolation.md index bdf7dd253..63e95659e 100644 --- a/docs/reference/koin-core/context-isolation.md +++ b/docs/reference/koin-core/context-isolation.md @@ -2,6 +2,7 @@ title: Context Isolation --- +## What Context Isolation? For SDK Makers, you can also work with Koin in a non-global way: use Koin for the DI of your library and avoid any conflict by people using your library and Koin by isolating your context. @@ -53,3 +54,23 @@ class MyKoinComponent : IsolatedKoinComponent(){ // inject & get will target MyKoinContext } ``` + +## Testing + +To test classes that are retrieving dependencies with `by inject()` delegate override `getKoin()` method and define custom Koin module: + +```kotlin +class MyClassTest : KoinTest { + // Koin Context used to retrieve bindings + override fun getKoin(): Koin = MyIsolatedKoinContext.koin + + @Before + fun setUp() { + val module = module { + // Register dependencies + } + + koin.loadModules(listOf(module)) + } +} +``` From 8de11809f0ebd1c499038061500369f57aa95758 Mon Sep 17 00:00:00 2001 From: Igor Wojda Date: Thu, 11 Jul 2024 16:34:32 +0200 Subject: [PATCH 2/2] Update context-isolation.md --- docs/reference/koin-core/context-isolation.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/docs/reference/koin-core/context-isolation.md b/docs/reference/koin-core/context-isolation.md index 63e95659e..99a38cba4 100644 --- a/docs/reference/koin-core/context-isolation.md +++ b/docs/reference/koin-core/context-isolation.md @@ -61,11 +61,12 @@ To test classes that are retrieving dependencies with `by inject()` delegate ove ```kotlin class MyClassTest : KoinTest { - // Koin Context used to retrieve bindings + // Koin Context used to retrieve dependencies override fun getKoin(): Koin = MyIsolatedKoinContext.koin @Before fun setUp() { + // Define custom Koin module val module = module { // Register dependencies }