Issue#67 Extract ActivityScenario.safeClose into separate module

This commit is contained in:
Gergely Hegedus 2022-05-27 15:12:59 +03:00
parent 689aee9702
commit 1c0153db75
8 changed files with 15 additions and 9 deletions

View file

@ -19,7 +19,7 @@ import org.fnives.test.showcase.testutils.idling.Disposable
import org.fnives.test.showcase.testutils.idling.IdlingResourceDisposable
import org.fnives.test.showcase.testutils.idling.MainDispatcherTestRule.Companion.advanceUntilIdleWithIdlingResources
import org.fnives.test.showcase.testutils.idling.OkHttp3IdlingResource
import org.fnives.test.showcase.testutils.safeClose
import org.fnives.test.showcase.android.testutil.activity.safeClose
import org.fnives.test.showcase.testutils.storage.TestDatabaseInitialization
import org.fnives.test.showcase.ui.auth.AuthActivity
import org.junit.After

View file

@ -7,7 +7,7 @@ import androidx.test.runner.intent.IntentStubberRegistry
import org.fnives.test.showcase.network.mockserver.MockServerScenarioSetup
import org.fnives.test.showcase.network.mockserver.scenario.auth.AuthScenario
import org.fnives.test.showcase.testutils.idling.MainDispatcherTestRule
import org.fnives.test.showcase.testutils.safeClose
import org.fnives.test.showcase.android.testutil.activity.safeClose
import org.fnives.test.showcase.ui.auth.AuthActivity
import org.fnives.test.showcase.ui.home.HomeRobot
import org.fnives.test.showcase.ui.home.MainActivity

View file

@ -12,7 +12,7 @@ import org.fnives.test.showcase.testutils.idling.AsyncDiffUtilInstantTestRule
import org.fnives.test.showcase.testutils.idling.MainDispatcherTestRule
import org.fnives.test.showcase.testutils.idling.loopMainThreadFor
import org.fnives.test.showcase.testutils.idling.loopMainThreadUntilIdleWithIdlingResources
import org.fnives.test.showcase.testutils.safeClose
import org.fnives.test.showcase.android.testutil.activity.safeClose
import org.fnives.test.showcase.testutils.statesetup.SetupAuthenticationState.setupLogin
import org.junit.After
import org.junit.Before

View file

@ -7,7 +7,7 @@ import org.fnives.test.showcase.R
import org.fnives.test.showcase.network.mockserver.scenario.auth.AuthScenario
import org.fnives.test.showcase.testutils.MockServerScenarioSetupResetingTestRule
import org.fnives.test.showcase.testutils.idling.MainDispatcherTestRule
import org.fnives.test.showcase.testutils.safeClose
import org.fnives.test.showcase.android.testutil.activity.safeClose
import org.fnives.test.showcase.ui.auth.AuthActivity
import org.junit.After
import org.junit.Before

View file

@ -6,7 +6,7 @@ import androidx.test.espresso.intent.Intents
import androidx.test.ext.junit.runners.AndroidJUnit4
import org.fnives.test.showcase.testutils.MockServerScenarioSetupResetingTestRule
import org.fnives.test.showcase.testutils.idling.MainDispatcherTestRule
import org.fnives.test.showcase.testutils.safeClose
import org.fnives.test.showcase.android.testutil.activity.safeClose
import org.fnives.test.showcase.testutils.statesetup.SetupAuthenticationState.setupLogin
import org.fnives.test.showcase.testutils.statesetup.SetupAuthenticationState.setupLogout
import org.junit.After

View file

@ -21,7 +21,7 @@ project.ext {
okhttp_version = "4.9.3"
moshi_version = "1.13.0"
testing_androidx_code_version = "1.4.0"
androidx_test_version = "1.4.0"
testing_androidx_junit_version = "1.1.3"
arch_core_version = "2.1.0"
testing_livedata_version = "1.2.0"

View file

@ -31,4 +31,5 @@ android {
dependencies {
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-test:$coroutines_version"
implementation "androidx.test:core:$androidx_test_version"
}

View file

@ -1,19 +1,24 @@
package org.fnives.test.showcase.testutils
package org.fnives.test.showcase.android.testutil.activity
import android.app.Activity
import androidx.test.core.app.ActivityScenario
/**
* Workaround for issue: https://github.com/android/android-test/issues/676.
*
* Call this instead of ActivityScenario.close().
*/
fun <T : Activity> ActivityScenario<T>.safeClose() {
workaroundForActivityScenarioCLoseLockingUp()
close()
}
/**
* This should not be needed, we shouldn't use sleep ever.
* This should not be needed, we shouldn't use sleep basically ever.
* However, it seems to be and issue described here: https://github.com/android/android-test/issues/676
*
* If an activity is finished in code, the ActivityScenario.close() can hang 30 to 45 seconds.
* This sleeps let's the Activity finish it state change and unlocks the ActivityScenario.
* This sleep let's the Activity finish it's state change and unlocks the ActivityScenario.
*
* As soon as that issue is closed, this should be removed as well.
*/