summaryrefslogtreecommitdiffhomepage
path: root/android/lib/common-test/src
diff options
context:
space:
mode:
authorDavid Göransson <david.goransson@mullvad.net>2025-08-05 10:15:27 +0200
committerDavid Göransson <david.goransson@mullvad.net>2025-08-05 10:15:27 +0200
commitf240b49d638f3f9932de70dbb00d108e33b7670f (patch)
tree75a71833287de24104ee99b4e19b5a90f74bb3e2 /android/lib/common-test/src
parentbeed5dc2c6e161d431bd455ff42e262899224bd4 (diff)
parent25d23887cc7f4fdd2e11cb39366489d49f33eab7 (diff)
downloadmullvadvpn-f240b49d638f3f9932de70dbb00d108e33b7670f.tar.xz
mullvadvpn-f240b49d638f3f9932de70dbb00d108e33b7670f.zip
Merge branch 'flaky-test-addtimeviewmodeltest-droid-2101'
Diffstat (limited to 'android/lib/common-test/src')
-rw-r--r--android/lib/common-test/src/main/java/net/mullvad/mullvadvpn/lib/common/test/TestCoroutineRule.kt6
1 files changed, 6 insertions, 0 deletions
diff --git a/android/lib/common-test/src/main/java/net/mullvad/mullvadvpn/lib/common/test/TestCoroutineRule.kt b/android/lib/common-test/src/main/java/net/mullvad/mullvadvpn/lib/common/test/TestCoroutineRule.kt
index 34d6739119..c73516f72d 100644
--- a/android/lib/common-test/src/main/java/net/mullvad/mullvadvpn/lib/common/test/TestCoroutineRule.kt
+++ b/android/lib/common-test/src/main/java/net/mullvad/mullvadvpn/lib/common/test/TestCoroutineRule.kt
@@ -10,6 +10,12 @@ import org.junit.jupiter.api.extension.AfterEachCallback
import org.junit.jupiter.api.extension.BeforeEachCallback
import org.junit.jupiter.api.extension.ExtensionContext
+/**
+ * Should be applied to any test class that has a test subject that uses the main dispatcher. This
+ * is the default dispatcher for coroutines on Android and is for example used by the
+ * viewModelScope. This avoids test flakiness due to the test dispatcher eagerly starting coroutines
+ * instead of waiting for runCurrent for them to start.
+ */
@OptIn(ExperimentalCoroutinesApi::class)
class TestCoroutineRule(val testDispatcher: TestDispatcher = UnconfinedTestDispatcher()) :
BeforeEachCallback, AfterEachCallback {