From cdb1d253067b7977ac19883119edf2d95d7766e4 Mon Sep 17 00:00:00 2001 From: blue928sky Date: Mon, 23 Sep 2024 10:08:31 +0900 Subject: [PATCH] Move Android instrumented test NiaAppStateTest to unit test Change-Id: I0a84dc37184a9ea7d4c18fa598bc447b0c48eb62 --- app/build.gradle.kts | 3 ++- .../samples/apps/nowinandroid/ui/NiaAppStateTest.kt | 11 ++++++++--- 2 files changed, 10 insertions(+), 4 deletions(-) rename app/src/{androidTest => testDemo}/kotlin/com/google/samples/apps/nowinandroid/ui/NiaAppStateTest.kt (94%) diff --git a/app/build.gradle.kts b/app/build.gradle.kts index 5434df8c2..5b131b5d6 100644 --- a/app/build.gradle.kts +++ b/app/build.gradle.kts @@ -119,15 +119,16 @@ dependencies { testImplementation(projects.sync.syncTest) testImplementation(libs.kotlin.test) + testDemoImplementation(libs.androidx.navigation.testing) testDemoImplementation(libs.robolectric) testDemoImplementation(libs.roborazzi) testDemoImplementation(projects.core.screenshotTesting) + testDemoImplementation(projects.core.testing) androidTestImplementation(projects.core.testing) androidTestImplementation(projects.core.dataTest) androidTestImplementation(projects.core.datastoreTest) androidTestImplementation(libs.androidx.test.espresso.core) - androidTestImplementation(libs.androidx.navigation.testing) androidTestImplementation(libs.androidx.compose.ui.test) androidTestImplementation(libs.hilt.android.testing) androidTestImplementation(libs.kotlin.test) diff --git a/app/src/androidTest/kotlin/com/google/samples/apps/nowinandroid/ui/NiaAppStateTest.kt b/app/src/testDemo/kotlin/com/google/samples/apps/nowinandroid/ui/NiaAppStateTest.kt similarity index 94% rename from app/src/androidTest/kotlin/com/google/samples/apps/nowinandroid/ui/NiaAppStateTest.kt rename to app/src/testDemo/kotlin/com/google/samples/apps/nowinandroid/ui/NiaAppStateTest.kt index c2c74458d..c6ddb54fb 100644 --- a/app/src/androidTest/kotlin/com/google/samples/apps/nowinandroid/ui/NiaAppStateTest.kt +++ b/app/src/testDemo/kotlin/com/google/samples/apps/nowinandroid/ui/NiaAppStateTest.kt @@ -31,6 +31,8 @@ import com.google.samples.apps.nowinandroid.core.testing.repository.TestNewsRepo import com.google.samples.apps.nowinandroid.core.testing.repository.TestUserDataRepository import com.google.samples.apps.nowinandroid.core.testing.util.TestNetworkMonitor import com.google.samples.apps.nowinandroid.core.testing.util.TestTimeZoneMonitor +import dagger.hilt.android.testing.HiltAndroidTest +import dagger.hilt.android.testing.HiltTestApplication import kotlinx.coroutines.flow.collect import kotlinx.coroutines.launch import kotlinx.coroutines.test.UnconfinedTestDispatcher @@ -38,15 +40,18 @@ import kotlinx.coroutines.test.runTest import kotlinx.datetime.TimeZone import org.junit.Rule import org.junit.Test +import org.junit.runner.RunWith +import org.robolectric.RobolectricTestRunner +import org.robolectric.annotation.Config import kotlin.test.assertEquals import kotlin.test.assertTrue /** * Tests [NiaAppState]. - * - * Note: This could become an unit test if Robolectric is added to the project and the Context - * is faked. */ +@RunWith(RobolectricTestRunner::class) +@Config(application = HiltTestApplication::class) +@HiltAndroidTest class NiaAppStateTest { @get:Rule