diff --git a/app/build.gradle b/app/build.gradle index e7faf43..37ae54c 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -110,6 +110,7 @@ dependencies { androidTestImplementation testFixtures(project(':core')) implementation project(':test-util-shared-robolectric') androidTestImplementation project(':test-util-shared-android') - + implementation project(':test-util-android') + androidTestImplementation project(':test-util-android') } diff --git a/app/src/sharedTest/java/org/fnives/test/showcase/testutils/idling/DispatcherTestRule.kt b/app/src/sharedTest/java/org/fnives/test/showcase/testutils/idling/DispatcherTestRule.kt index 8d2f0bc..26a7d43 100644 --- a/app/src/sharedTest/java/org/fnives/test/showcase/testutils/idling/DispatcherTestRule.kt +++ b/app/src/sharedTest/java/org/fnives/test/showcase/testutils/idling/DispatcherTestRule.kt @@ -3,7 +3,7 @@ package org.fnives.test.showcase.testutils.idling import kotlinx.coroutines.ExperimentalCoroutinesApi import kotlinx.coroutines.test.StandardTestDispatcher import kotlinx.coroutines.test.TestDispatcher -import org.fnives.test.showcase.testutils.runOnUIAwaitOnCurrent +import org.fnives.test.showcase.android.testutil.synchronization.runOnUIAwaitOnCurrent import org.fnives.test.showcase.testutils.storage.TestDatabaseInitialization import org.junit.rules.TestRule import org.junit.runner.Description diff --git a/app/src/sharedTest/java/org/fnives/test/showcase/testutils/idling/MainDispatcherTestRule.kt b/app/src/sharedTest/java/org/fnives/test/showcase/testutils/idling/MainDispatcherTestRule.kt index de21704..59a1fb9 100644 --- a/app/src/sharedTest/java/org/fnives/test/showcase/testutils/idling/MainDispatcherTestRule.kt +++ b/app/src/sharedTest/java/org/fnives/test/showcase/testutils/idling/MainDispatcherTestRule.kt @@ -6,7 +6,7 @@ import kotlinx.coroutines.test.StandardTestDispatcher import kotlinx.coroutines.test.TestDispatcher import kotlinx.coroutines.test.resetMain import kotlinx.coroutines.test.setMain -import org.fnives.test.showcase.testutils.runOnUIAwaitOnCurrent +import org.fnives.test.showcase.android.testutil.synchronization.runOnUIAwaitOnCurrent import org.fnives.test.showcase.testutils.storage.TestDatabaseInitialization import org.junit.rules.TestRule import org.junit.runner.Description diff --git a/app/src/sharedTest/java/org/fnives/test/showcase/testutils/viewactions/PullToRefresh.kt b/app/src/sharedTest/java/org/fnives/test/showcase/testutils/viewactions/PullToRefresh.kt index fa8a14c..d1b4751 100644 --- a/app/src/sharedTest/java/org/fnives/test/showcase/testutils/viewactions/PullToRefresh.kt +++ b/app/src/sharedTest/java/org/fnives/test/showcase/testutils/viewactions/PullToRefresh.kt @@ -5,7 +5,7 @@ import androidx.swiperefreshlayout.widget.SwipeRefreshLayout import androidx.swiperefreshlayout.widget.listener import androidx.test.espresso.UiController import androidx.test.espresso.ViewAction -import org.fnives.test.showcase.testutils.runOnUIAwaitOnCurrent +import org.fnives.test.showcase.android.testutil.synchronization.runOnUIAwaitOnCurrent import org.hamcrest.BaseMatcher import org.hamcrest.CoreMatchers.isA import org.hamcrest.Description diff --git a/gradlescripts/testdependencies.gradle b/gradlescripts/testdependencies.gradle index 991af51..c43b981 100644 --- a/gradlescripts/testdependencies.gradle +++ b/gradlescripts/testdependencies.gradle @@ -43,7 +43,7 @@ project.ext { def testing_androidx_junit_version = propertyOrNull('androidx_junit_version') ?: "1.1.3" def testing_espresso_version = propertyOrNull('espresso_version') ?: "3.4.0" def testing_androidx_arch_core_version = propertyOrNull('arch_core_version') ?: "2.1.0" - def test_coroutines_version = propertyOrNull('coroutines_versionx') ?: "1.6.0" + def test_coroutines_version = propertyOrNull('coroutines_version') ?: "1.6.0" def testing_kotlin_mockito_version = propertyOrNull('mockito_version') ?: "3.1.0" def testing_koin_version = propertyOrNull('koin_version') ?: "3.1.2" def testing_json_assert_version = propertyOrNull('json_assert_version') ?: "1.5.0" diff --git a/settings.gradle b/settings.gradle index 1b941c4..7e8bd01 100644 --- a/settings.gradle +++ b/settings.gradle @@ -6,3 +6,4 @@ include ':network' include ':app' include ':test-util-shared-android' include ':test-util-shared-robolectric' +include ':test-util-android' diff --git a/test-util-android/.gitignore b/test-util-android/.gitignore new file mode 100644 index 0000000..42afabf --- /dev/null +++ b/test-util-android/.gitignore @@ -0,0 +1 @@ +/build \ No newline at end of file diff --git a/test-util-android/build.gradle b/test-util-android/build.gradle new file mode 100644 index 0000000..83ea82d --- /dev/null +++ b/test-util-android/build.gradle @@ -0,0 +1,34 @@ +plugins { + id 'com.android.library' + id 'org.jetbrains.kotlin.android' +} + +android { + compileSdk 31 + + defaultConfig { + minSdk 21 + targetSdk 31 + + testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" + consumerProguardFiles "consumer-rules.pro" + } + + buildTypes { + release { + minifyEnabled false + proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' + } + } + compileOptions { + sourceCompatibility JavaVersion.VERSION_1_8 + targetCompatibility JavaVersion.VERSION_1_8 + } + kotlinOptions { + jvmTarget = '1.8' + } +} + +dependencies { + implementation "org.jetbrains.kotlinx:kotlinx-coroutines-test:$coroutines_version" +} \ No newline at end of file diff --git a/test-util-android/consumer-rules.pro b/test-util-android/consumer-rules.pro new file mode 100644 index 0000000..e69de29 diff --git a/test-util-android/proguard-rules.pro b/test-util-android/proguard-rules.pro new file mode 100644 index 0000000..481bb43 --- /dev/null +++ b/test-util-android/proguard-rules.pro @@ -0,0 +1,21 @@ +# Add project specific ProGuard rules here. +# You can control the set of applied configuration files using the +# proguardFiles setting in build.gradle. +# +# For more details, see +# http://developer.android.com/guide/developing/tools/proguard.html + +# If your project uses WebView with JS, uncomment the following +# and specify the fully qualified class name to the JavaScript interface +# class: +#-keepclassmembers class fqcn.of.javascript.interface.for.webview { +# public *; +#} + +# Uncomment this to preserve the line number information for +# debugging stack traces. +#-keepattributes SourceFile,LineNumberTable + +# If you keep the line number information, uncomment this to +# hide the original source file name. +#-renamesourcefileattribute SourceFile \ No newline at end of file diff --git a/test-util-android/src/main/AndroidManifest.xml b/test-util-android/src/main/AndroidManifest.xml new file mode 100644 index 0000000..80e5dbb --- /dev/null +++ b/test-util-android/src/main/AndroidManifest.xml @@ -0,0 +1,5 @@ + + + + \ No newline at end of file diff --git a/app/src/sharedTest/java/org/fnives/test/showcase/testutils/doBlockinglyOnMainThread.kt b/test-util-android/src/main/java/org/fnives/test/showcase/android/testutil/synchronization/doBlockinglyOnMainThread.kt similarity index 69% rename from app/src/sharedTest/java/org/fnives/test/showcase/testutils/doBlockinglyOnMainThread.kt rename to test-util-android/src/main/java/org/fnives/test/showcase/android/testutil/synchronization/doBlockinglyOnMainThread.kt index f8a8e91..5df6bd8 100644 --- a/app/src/sharedTest/java/org/fnives/test/showcase/testutils/doBlockinglyOnMainThread.kt +++ b/test-util-android/src/main/java/org/fnives/test/showcase/android/testutil/synchronization/doBlockinglyOnMainThread.kt @@ -1,10 +1,15 @@ -package org.fnives.test.showcase.testutils +package org.fnives.test.showcase.android.testutil.synchronization import android.os.Handler import android.os.Looper import kotlinx.coroutines.CompletableDeferred import kotlinx.coroutines.runBlocking +/** + * Runs the given action on the MainThread and blocks currentThread, until it is completed. + * + * It is safe to call this from the MainThread. + */ fun runOnUIAwaitOnCurrent(action: () -> Unit) { if (Looper.myLooper() === Looper.getMainLooper()) { action()