From 7cc9368a67a3dd328ad60b8964bcfa5e3b60d392 Mon Sep 17 00:00:00 2001 From: Renaud BEURET Date: Tue, 2 Apr 2024 18:48:10 +0200 Subject: [PATCH] =?UTF-8?q?[ADD]=20R=C3=A8gle=20qui=20remplace=20le=20disp?= =?UTF-8?q?atcheur=20pour=20les=20tests?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .idea/modules.xml | 8 ------- .../testRules/MainDispatcherRule.kt | 24 +++++++++++++++++++ 2 files changed, 24 insertions(+), 8 deletions(-) delete mode 100644 .idea/modules.xml create mode 100644 android/app/src/test/java/fr/iut/sciencequest/testRules/MainDispatcherRule.kt diff --git a/.idea/modules.xml b/.idea/modules.xml deleted file mode 100644 index c5871cc..0000000 --- a/.idea/modules.xml +++ /dev/null @@ -1,8 +0,0 @@ - - - - - - - - \ No newline at end of file diff --git a/android/app/src/test/java/fr/iut/sciencequest/testRules/MainDispatcherRule.kt b/android/app/src/test/java/fr/iut/sciencequest/testRules/MainDispatcherRule.kt new file mode 100644 index 0000000..e571a61 --- /dev/null +++ b/android/app/src/test/java/fr/iut/sciencequest/testRules/MainDispatcherRule.kt @@ -0,0 +1,24 @@ +package fr.iut.sciencequest.testRules + +import kotlinx.coroutines.Dispatchers +import kotlinx.coroutines.ExperimentalCoroutinesApi +import kotlinx.coroutines.test.TestDispatcher +import kotlinx.coroutines.test.UnconfinedTestDispatcher +import kotlinx.coroutines.test.resetMain +import kotlinx.coroutines.test.setMain +import org.junit.rules.TestWatcher +import org.junit.runner.Description + +// simule le dispatcheurs utilisé par les ViewModels +@OptIn(ExperimentalCoroutinesApi::class) +class MainDispatcherRule( + private val testDispatcher: TestDispatcher = UnconfinedTestDispatcher() +) : TestWatcher() { + override fun starting(description: Description) { + Dispatchers.setMain(testDispatcher) + } + + override fun finished(description: Description) { + Dispatchers.resetMain() + } +} \ No newline at end of file