diff --git a/Examples/DemoApp/buildSrc/src/main/kotlin/Config.kt b/Examples/DemoApp/buildSrc/src/main/kotlin/Config.kt index 740beb4..b2218cc 100644 --- a/Examples/DemoApp/buildSrc/src/main/kotlin/Config.kt +++ b/Examples/DemoApp/buildSrc/src/main/kotlin/Config.kt @@ -68,7 +68,7 @@ object AndroidX { object Coroutines { - private const val version = "1.3.3" + const val version = "1.3.3" const val common = "org.jetbrains.kotlinx:kotlinx-coroutines-core-common:$version" const val android = "org.jetbrains.kotlinx:kotlinx-coroutines-android:$version" @@ -108,8 +108,6 @@ object Ktor { object Tests { const val junit = "junit:junit:4.13" + const val coroutines = "org.jetbrains.kotlinx:kotlinx-coroutines-test:${Coroutines.version}" const val mockk = "io.mockk:mockk:1.9.3" - const val androidxTestCore = "androidx.test:core:1.2.0" - const val androidxTestJuint = "androidx.test.ext:junit:1.1.1" - const val robolectric = "org.robolectric:robolectric:4.0" -} \ No newline at end of file +} diff --git a/Examples/DemoApp/shared/build.gradle.kts b/Examples/DemoApp/shared/build.gradle.kts index 860c2ea..2840b8b 100644 --- a/Examples/DemoApp/shared/build.gradle.kts +++ b/Examples/DemoApp/shared/build.gradle.kts @@ -77,21 +77,16 @@ kotlin { getByName("commonTest").dependencies { implementation(kotlin("test-common", Build.Versions.kotlin)) + implementation(kotlin("test-junit", Build.Versions.kotlin)) implementation(kotlin("test-annotations-common", Build.Versions.kotlin)) implementation(Coroutines.common) + implementation(Tests.coroutines) implementation(Tests.mockk) } getByName("androidTest").dependencies { - implementation(kotlin("test", Build.Versions.kotlin)) - implementation(kotlin("test-junit", Build.Versions.kotlin)) - implementation(kotlin("test-annotations-common", Build.Versions.kotlin)) implementation(Coroutines.android) - implementation(Tests.junit) - implementation(Tests.mockk) - implementation(Tests.androidxTestCore) - implementation(Tests.androidxTestJuint) - implementation(Tests.robolectric) + implementation(Tests.coroutines) } getByName("iosTest").dependencies { diff --git a/Examples/DemoApp/shared/src/androidTest/kotlin/com/jtouzy/demo/common/coroutines.kt b/Examples/DemoApp/shared/src/androidTest/kotlin/com/jtouzy/demo/common/coroutines.kt index 0c3bd78..ab2ddd4 100644 --- a/Examples/DemoApp/shared/src/androidTest/kotlin/com/jtouzy/demo/common/coroutines.kt +++ b/Examples/DemoApp/shared/src/androidTest/kotlin/com/jtouzy/demo/common/coroutines.kt @@ -1,7 +1,10 @@ package com.jtouzy.demo.common +import kotlinx.coroutines.ExperimentalCoroutinesApi import kotlinx.coroutines.runBlocking +import kotlinx.coroutines.test.TestCoroutineDispatcher +@ExperimentalCoroutinesApi internal actual fun runTest(block: suspend () -> T): T { - return runBlocking { block() } + return runBlocking(TestCoroutineDispatcher()) { block() } } diff --git a/Examples/DemoApp/shared/src/androidTest/kotlin/com/jtouzy/demo/ui/characters/TestOverridesJVM.kt b/Examples/DemoApp/shared/src/androidTest/kotlin/com/jtouzy/demo/ui/characters/TestOverridesJVM.kt deleted file mode 100644 index 65fbe09..0000000 --- a/Examples/DemoApp/shared/src/androidTest/kotlin/com/jtouzy/demo/ui/characters/TestOverridesJVM.kt +++ /dev/null @@ -1,7 +0,0 @@ -package com.jtouzy.demo.ui.characters - -import androidx.test.ext.junit.runners.AndroidJUnit4 -import org.junit.runner.RunWith - -@RunWith(AndroidJUnit4::class) -class CharactersPresenterTestJVM : CharactersPresenterTest() diff --git a/Examples/DemoApp/shared/src/commonTest/kotlin/com/jtouzy/demo/ui/characters/CharactersPresenterTest.kt b/Examples/DemoApp/shared/src/commonTest/kotlin/com/jtouzy/demo/ui/characters/CharactersPresenterTest.kt index 7ea66df..213fb10 100644 --- a/Examples/DemoApp/shared/src/commonTest/kotlin/com/jtouzy/demo/ui/characters/CharactersPresenterTest.kt +++ b/Examples/DemoApp/shared/src/commonTest/kotlin/com/jtouzy/demo/ui/characters/CharactersPresenterTest.kt @@ -5,13 +5,10 @@ import com.jtouzy.demo.common.runTest import com.jtouzy.demo.network.dto.CharacterDto import com.jtouzy.demo.ui.Store import com.jtouzy.demo.ui.model.Character -import io.mockk.coEvery -import io.mockk.coVerifyOrder -import io.mockk.mockk -import io.mockk.spyk +import io.mockk.* import kotlin.test.Test -open class CharactersPresenterTest { +class CharactersPresenterTest { private val dtoCharacters = listOf( CharacterDto("Toto", "url"), @@ -33,9 +30,9 @@ open class CharactersPresenterTest { @Test fun `should return characters when call is successful`() { runTest { - presenter.loadCharacters() + presenter.asyncLoadCharacters() - coVerifyOrder { + verifyOrder { store.viewState = CharactersViewState.Loading store.viewState = CharactersViewState.Content(characters) } diff --git a/Examples/DemoApp/shared/src/iosTest/kotlin/com/jtouzy/demo/ui/TestOverridesNative.kt b/Examples/DemoApp/shared/src/iosTest/kotlin/com/jtouzy/demo/ui/TestOverridesNative.kt deleted file mode 100644 index 6e16395..0000000 --- a/Examples/DemoApp/shared/src/iosTest/kotlin/com/jtouzy/demo/ui/TestOverridesNative.kt +++ /dev/null @@ -1,5 +0,0 @@ -package com.jtouzy.demo.ui - -import com.jtouzy.demo.ui.characters.CharactersPresenterTest - -class CharactersPresenterTestNative : CharactersPresenterTest()