diff options
| author | Jonatan Rhodin <jonatan.rhodin@mullvad.net> | 2023-09-01 08:45:14 +0200 |
|---|---|---|
| committer | Jonatan Rhodin <jonatan.rhodin@mullvad.net> | 2023-09-05 15:48:26 +0200 |
| commit | a390e468068669dc1adde1d009bf5c20205a1060 (patch) | |
| tree | e2be2c2e1a81045926420b68c43e7a868a994630 /android/lib | |
| parent | 72870f4ef00a27c35a17f300a1fa3dfaaee49a3d (diff) | |
| download | mullvadvpn-a390e468068669dc1adde1d009bf5c20205a1060.tar.xz mullvadvpn-a390e468068669dc1adde1d009bf5c20205a1060.zip | |
Move test utils to its own module
Diffstat (limited to 'android/lib')
3 files changed, 71 insertions, 0 deletions
diff --git a/android/lib/common-test/build.gradle.kts b/android/lib/common-test/build.gradle.kts new file mode 100644 index 0000000000..ca820dbadd --- /dev/null +++ b/android/lib/common-test/build.gradle.kts @@ -0,0 +1,32 @@ +plugins { + id(Dependencies.Plugin.androidLibraryId) + id(Dependencies.Plugin.kotlinAndroidId) +} + +android { + namespace = "net.mullvad.mullvadvpn.lib.common.test" + compileSdk = Versions.Android.compileSdkVersion + + defaultConfig { + minSdk = Versions.Android.minSdkVersion + } + + compileOptions { + sourceCompatibility = JavaVersion.VERSION_17 + targetCompatibility = JavaVersion.VERSION_17 + } + + kotlinOptions { jvmTarget = Versions.jvmTarget } + + lint { + lintConfig = file("${rootProject.projectDir}/config/lint.xml") + abortOnError = true + warningsAsErrors = true + } +} + +dependencies { + implementation(Dependencies.Kotlin.test) + implementation(Dependencies.KotlinX.coroutinesTest) + implementation(Dependencies.junit) +} 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 new file mode 100644 index 0000000000..2488aab66e --- /dev/null +++ b/android/lib/common-test/src/main/java/net/mullvad/mullvadvpn/lib/common/test/TestCoroutineRule.kt @@ -0,0 +1,23 @@ +package net.mullvad.mullvadvpn.lib.common.test + +import kotlinx.coroutines.Dispatchers +import kotlinx.coroutines.test.TestCoroutineDispatcher +import kotlinx.coroutines.test.resetMain +import kotlinx.coroutines.test.setMain +import org.junit.rules.TestWatcher +import org.junit.runner.Description + +class TestCoroutineRule(val testDispatcher: TestCoroutineDispatcher = TestCoroutineDispatcher()) : + TestWatcher() { + + override fun starting(description: Description?) { + super.starting(description) + Dispatchers.setMain(testDispatcher) + } + + override fun finished(description: Description?) { + super.finished(description) + Dispatchers.resetMain() + testDispatcher.cleanupTestCoroutines() + } +} diff --git a/android/lib/common-test/src/main/java/net/mullvad/mullvadvpn/lib/common/test/TestUtils.kt b/android/lib/common-test/src/main/java/net/mullvad/mullvadvpn/lib/common/test/TestUtils.kt new file mode 100644 index 0000000000..8d09cdf22c --- /dev/null +++ b/android/lib/common-test/src/main/java/net/mullvad/mullvadvpn/lib/common/test/TestUtils.kt @@ -0,0 +1,16 @@ +package net.mullvad.mullvadvpn.lib.common.test + +import kotlin.test.assertTrue + +fun <T> assertLists(expected: List<T>, actual: List<T>, message: String? = null) = + assertTrue( + expected.size == actual.size && + expected.containsAll(actual) && + actual.containsAll(expected), + message + ?: """Expected list should have same size and contains same items. + | Expected(${expected.size}): $expected + | Actual(${actual.size}) : $actual + """ + .trimMargin() + ) |
