summaryrefslogtreecommitdiffhomepage
path: root/android/lib/common-test
diff options
context:
space:
mode:
authorDavid Göransson <david.goransson90@gmail.com>2024-01-10 15:04:30 +0100
committerJonatan Rhodin <jonatan.rhodin@mullvad.net>2024-01-11 09:51:38 +0100
commitabb2b79a830fbdaa0afa22a5cb2c272fa94a538c (patch)
treeecc720997aeb3568b9d02a2c7c099ea220d37c3f /android/lib/common-test
parentb5decd12a264c3e37092211eb0951dac6c640670 (diff)
downloadmullvadvpn-abb2b79a830fbdaa0afa22a5cb2c272fa94a538c.tar.xz
mullvadvpn-abb2b79a830fbdaa0afa22a5cb2c272fa94a538c.zip
Migrate app unit tests to Junit5
Diffstat (limited to 'android/lib/common-test')
-rw-r--r--android/lib/common-test/build.gradle.kts12
-rw-r--r--android/lib/common-test/src/main/java/net/mullvad/mullvadvpn/lib/common/test/TestCoroutineRule.kt14
2 files changed, 17 insertions, 9 deletions
diff --git a/android/lib/common-test/build.gradle.kts b/android/lib/common-test/build.gradle.kts
index 3d0ef6c028..6e3fc7c02f 100644
--- a/android/lib/common-test/build.gradle.kts
+++ b/android/lib/common-test/build.gradle.kts
@@ -21,10 +21,20 @@ android {
abortOnError = true
warningsAsErrors = true
}
+
+ packaging {
+ resources {
+ pickFirsts += setOf(
+ // Fixes packaging error caused by: jetified-junit-*
+ "META-INF/LICENSE.md",
+ "META-INF/LICENSE-notice.md"
+ )
+ }
+ }
}
dependencies {
implementation(Dependencies.Kotlin.test)
implementation(Dependencies.KotlinX.coroutinesTest)
- implementation(Dependencies.junit)
+ implementation(Dependencies.junitApi)
}
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 d04983be26..34d6739119 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
@@ -6,22 +6,20 @@ 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
+import org.junit.jupiter.api.extension.AfterEachCallback
+import org.junit.jupiter.api.extension.BeforeEachCallback
+import org.junit.jupiter.api.extension.ExtensionContext
@OptIn(ExperimentalCoroutinesApi::class)
class TestCoroutineRule(val testDispatcher: TestDispatcher = UnconfinedTestDispatcher()) :
- TestWatcher() {
+ BeforeEachCallback, AfterEachCallback {
- override fun starting(description: Description) {
- super.starting(description)
+ override fun beforeEach(var1: ExtensionContext?) {
Dispatchers.setMain(testDispatcher)
}
- override fun finished(description: Description) {
- super.finished(description)
+ override fun afterEach(var1: ExtensionContext?) {
Dispatchers.resetMain()
- // Replacement for cleanupTestCoroutines()
testDispatcher.scheduler.runCurrent()
}
}