From 9efa7f6cebbf39737e2bfcfb7c630a3d2bf3e0b8 Mon Sep 17 00:00:00 2001 From: Basler182 Date: Sun, 23 Jun 2024 14:11:30 +0200 Subject: [PATCH] added CoroutineTestRule() Signed-off-by: Basler182 --- .../stanford/bdh/engagehf/MainActivityViewModelTest.kt | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/app/src/test/kotlin/edu/stanford/bdh/engagehf/MainActivityViewModelTest.kt b/app/src/test/kotlin/edu/stanford/bdh/engagehf/MainActivityViewModelTest.kt index 60ddd0aa9..a92112d5d 100644 --- a/app/src/test/kotlin/edu/stanford/bdh/engagehf/MainActivityViewModelTest.kt +++ b/app/src/test/kotlin/edu/stanford/bdh/engagehf/MainActivityViewModelTest.kt @@ -4,6 +4,7 @@ import com.google.firebase.auth.FirebaseAuth import com.google.firebase.auth.FirebaseUser import edu.stanford.bdh.engagehf.navigation.AppNavigationEvent import edu.stanford.spezi.core.navigation.Navigator +import edu.stanford.spezi.core.testing.CoroutineTestRule import edu.stanford.spezi.core.testing.runTestUnconfined import edu.stanford.spezi.module.account.AccountEvents import edu.stanford.spezi.module.onboarding.OnboardingNavigationEvent @@ -13,17 +14,18 @@ import io.mockk.coVerify import io.mockk.every import io.mockk.mockk import io.mockk.slot -import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.ExperimentalCoroutinesApi import kotlinx.coroutines.flow.MutableSharedFlow -import kotlinx.coroutines.test.UnconfinedTestDispatcher -import kotlinx.coroutines.test.setMain import org.junit.Before +import org.junit.Rule import org.junit.Test @ExperimentalCoroutinesApi class MainActivityViewModelTest { + @get:Rule + val coroutineTestRule = CoroutineTestRule() + private lateinit var viewModel: MainActivityViewModel private val accountEvents: AccountEvents = mockk(relaxed = true) private val navigator: Navigator = mockk(relaxed = true) @@ -33,7 +35,6 @@ class MainActivityViewModelTest { @Before fun setUp() { - Dispatchers.setMain(UnconfinedTestDispatcher()) every { accountEvents.events } returns MutableSharedFlow() viewModel = MainActivityViewModel(accountEvents, navigator, firebaseAuth, pdfService) }