File tree Expand file tree Collapse file tree 5 files changed +45
-19
lines changed
main/java/com/hoc/flowmvi
test/java/com/hoc/flowmvi
feature-add/src/main/java/com/hoc/flowmvi/ui/add Expand file tree Collapse file tree 5 files changed +45
-19
lines changed Original file line number Diff line number Diff line change @@ -73,4 +73,5 @@ dependencies {
73
73
androidTestImplementation(deps.test.androidXSspresso)
74
74
75
75
addUnitTest()
76
+ testImplementation(deps.koin.testJunit4)
76
77
}
Original file line number Diff line number Diff line change @@ -15,6 +15,19 @@ import org.koin.core.context.startKoin
15
15
import org.koin.core.logger.Level
16
16
import kotlin.time.ExperimentalTime
17
17
18
+ @FlowPreview
19
+ @ExperimentalCoroutinesApi
20
+ @ExperimentalStdlibApi
21
+ @ExperimentalTime
22
+ val allModules = listOf (
23
+ coreModule,
24
+ dataModule,
25
+ domainModule,
26
+ mainModule,
27
+ addModule,
28
+ searchModule,
29
+ )
30
+
18
31
@Suppress(" unused" )
19
32
@ExperimentalStdlibApi
20
33
@FlowPreview
@@ -29,14 +42,7 @@ class App : Application() {
29
42
30
43
androidLogger(if (BuildConfig .DEBUG ) Level .DEBUG else Level .NONE )
31
44
32
- modules(
33
- coreModule,
34
- dataModule,
35
- domainModule,
36
- mainModule,
37
- addModule,
38
- searchModule,
39
- )
45
+ modules(allModules)
40
46
}
41
47
}
42
48
}
Original file line number Diff line number Diff line change 1
1
package com.hoc.flowmvi
2
2
3
+ import androidx.lifecycle.SavedStateHandle
4
+ import io.mockk.every
5
+ import io.mockk.mockkClass
6
+ import kotlinx.coroutines.ExperimentalCoroutinesApi
7
+ import kotlinx.coroutines.FlowPreview
8
+ import org.junit.Rule
9
+ import org.koin.test.check.checkKoinModules
10
+ import org.koin.test.mock.MockProviderRule
3
11
import kotlin.test.Test
4
- import kotlin.test.assertEquals
12
+ import kotlin.time.ExperimentalTime
5
13
6
- /* *
7
- * Example local unit test, which will execute on the development machine (host).
8
- *
9
- * See [testing documentation](http://d.android.com/tools/testing).
10
- */
14
+ @ExperimentalStdlibApi
15
+ @FlowPreview
16
+ @ExperimentalCoroutinesApi
17
+ @ExperimentalTime
11
18
class ExampleUnitTest {
19
+ @get:Rule
20
+ val mockProvider = MockProviderRule .create { clazz ->
21
+ mockkClass(clazz).also { o ->
22
+ if (clazz == SavedStateHandle ::class ) {
23
+ every { (o as SavedStateHandle ).get<Any ?>(any()) } returns null
24
+ }
25
+ }
26
+ }
27
+
12
28
@Test
13
- fun addition_isCorrect () {
14
- assertEquals(4 , 2 + 2 )
29
+ fun verifyKoinApp () {
30
+ checkKoinModules(allModules) {
31
+ withInstance<SavedStateHandle >()
32
+ }
15
33
}
16
34
}
Original file line number Diff line number Diff line change @@ -59,10 +59,11 @@ object deps {
59
59
}
60
60
61
61
object koin {
62
- private const val version = " 3.0.2 "
62
+ private const val version = " 3.1.3 "
63
63
64
64
const val core = " io.insert-koin:koin-core:$version "
65
65
const val android = " io.insert-koin:koin-android:$version "
66
+ const val testJunit4 = " io.insert-koin:koin-test-junit4:$version "
66
67
}
67
68
68
69
const val coil = " io.coil-kt:coil:1.2.1"
Original file line number Diff line number Diff line change @@ -24,11 +24,11 @@ import kotlinx.coroutines.flow.launchIn
24
24
import kotlinx.coroutines.flow.map
25
25
import kotlinx.coroutines.flow.merge
26
26
import kotlinx.coroutines.flow.onEach
27
- import org.koin.androidx.viewmodel.ext.android.stateViewModel
27
+ import org.koin.androidx.viewmodel.ext.android.viewModel
28
28
29
29
@ExperimentalCoroutinesApi
30
30
class AddActivity : AppCompatActivity (R .layout.activity_add) {
31
- private val addVM by stateViewModel <AddVM >()
31
+ private val addVM by viewModel <AddVM >()
32
32
private val addBinding by viewBinding<ActivityAddBinding >()
33
33
34
34
override fun onCreate (savedInstanceState : Bundle ? ) {
You can’t perform that action at this time.
0 commit comments