From 213778122c76e8ed3ff2ba57edfbc1ba6e11ab0a Mon Sep 17 00:00:00 2001 From: Harsh Shandilya Date: Mon, 19 Apr 2021 17:13:12 +0530 Subject: [PATCH] Migrate some tests to Robolectric (#1389) Signed-off-by: Harsh Shandilya --- app/build.gradle.kts | 1 + .../java/dev/msfjarvis/aps/util/totp/UriTotpFinderTest.kt | 5 +++++ .../msfjarvis/aps/util/viewmodel/StrictDomainRegexTest.kt | 5 +++++ gradle/libs.versions.toml | 1 + 4 files changed, 12 insertions(+) rename app/src/{androidTest => test}/java/dev/msfjarvis/aps/util/totp/UriTotpFinderTest.kt (88%) rename app/src/{androidTest => test}/java/dev/msfjarvis/aps/util/viewmodel/StrictDomainRegexTest.kt (91%) diff --git a/app/build.gradle.kts b/app/build.gradle.kts index 8b2b18f93..d54b5ea95 100644 --- a/app/build.gradle.kts +++ b/app/build.gradle.kts @@ -100,5 +100,6 @@ dependencies { androidTestImplementation(libs.bundles.testDependencies) androidTestImplementation(libs.bundles.androidTestDependencies) + testImplementation(libs.testing.robolectric) testImplementation(libs.bundles.testDependencies) } diff --git a/app/src/androidTest/java/dev/msfjarvis/aps/util/totp/UriTotpFinderTest.kt b/app/src/test/java/dev/msfjarvis/aps/util/totp/UriTotpFinderTest.kt similarity index 88% rename from app/src/androidTest/java/dev/msfjarvis/aps/util/totp/UriTotpFinderTest.kt rename to app/src/test/java/dev/msfjarvis/aps/util/totp/UriTotpFinderTest.kt index b89cf0ef4..f04913a15 100644 --- a/app/src/androidTest/java/dev/msfjarvis/aps/util/totp/UriTotpFinderTest.kt +++ b/app/src/test/java/dev/msfjarvis/aps/util/totp/UriTotpFinderTest.kt @@ -7,7 +7,12 @@ package dev.msfjarvis.aps.util.totp import kotlin.test.assertEquals import org.junit.Test +import org.junit.runner.RunWith +import org.robolectric.RobolectricTestRunner +import org.robolectric.annotation.Config +@RunWith(RobolectricTestRunner::class) +@Config(sdk = [23]) class UriTotpFinderTest { private val totpFinder = UriTotpFinder() diff --git a/app/src/androidTest/java/dev/msfjarvis/aps/util/viewmodel/StrictDomainRegexTest.kt b/app/src/test/java/dev/msfjarvis/aps/util/viewmodel/StrictDomainRegexTest.kt similarity index 91% rename from app/src/androidTest/java/dev/msfjarvis/aps/util/viewmodel/StrictDomainRegexTest.kt rename to app/src/test/java/dev/msfjarvis/aps/util/viewmodel/StrictDomainRegexTest.kt index 575c5aa7e..3d5111325 100644 --- a/app/src/androidTest/java/dev/msfjarvis/aps/util/viewmodel/StrictDomainRegexTest.kt +++ b/app/src/test/java/dev/msfjarvis/aps/util/viewmodel/StrictDomainRegexTest.kt @@ -8,10 +8,15 @@ import kotlin.test.assertFalse import kotlin.test.assertNull import kotlin.test.assertTrue import org.junit.Test +import org.junit.runner.RunWith +import org.robolectric.RobolectricTestRunner +import org.robolectric.annotation.Config private infix fun String.matchedForDomain(domain: String) = SearchableRepositoryViewModel.generateStrictDomainRegex(domain)?.containsMatchIn(this) == true +@RunWith(RobolectricTestRunner::class) +@Config(sdk = [23]) class StrictDomainRegexTest { @Test diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 80c27817f..829eae3d4 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -74,6 +74,7 @@ thirdparty-nonfree-googlePlayAuthApiPhone = "com.google.android.gms:play-service # Testing dependencies testing-junit = "junit:junit:4.13.2" testing-kotlintest-junit = { module = "org.jetbrains.kotlin:kotlin-test-junit", version.ref = "kotlin" } +testing-robolectric = "org.robolectric:robolectric:4.5.1" androidx-testing-rules = { module = "androidx.test:rules", version.ref="androidx_test" } androidx-testing-runner = { module = "androidx.test:runner", version.ref="androidx_test" } kotlin-coroutines-test = { module = "org.jetbrains.kotlinx:kotlinx-coroutines-test", version.ref = "coroutines" }