File tree Expand file tree Collapse file tree 2 files changed +43
-0
lines changed
owncloudApp/src/androidTest/java/com/owncloud/android Expand file tree Collapse file tree 2 files changed +43
-0
lines changed Original file line number Diff line number Diff line change @@ -20,6 +20,7 @@ import com.owncloud.android.testutil.OC_FILE_WITH_SYNC_INFO_AND_SPACE
2020import com.owncloud.android.testutil.OC_FILE_WITH_SYNC_INFO_AND_WITHOUT_PERSONAL_SPACE
2121import com.owncloud.android.testutil.OC_FILE_WITH_SYNC_INFO_AVAILABLE_OFFLINE
2222import com.owncloud.android.utils.DisplayUtils
23+ import com.owncloud.android.utils.RetryFlakyTestUntilSuccessRule
2324import com.owncloud.android.utils.matchers.assertVisibility
2425import com.owncloud.android.utils.matchers.isDisplayed
2526import com.owncloud.android.utils.matchers.withDrawable
@@ -29,6 +30,7 @@ import io.mockk.mockk
2930import kotlinx.coroutines.flow.MutableStateFlow
3031import org.junit.Before
3132import org.junit.Ignore
33+ import org.junit.Rule
3234import org.junit.Test
3335import org.koin.androidx.viewmodel.dsl.viewModel
3436import org.koin.core.context.startKoin
@@ -47,6 +49,10 @@ class FileDetailsFragmentTest {
4749 private var currentFileSyncInfo: MutableStateFlow <OCFileWithSyncInfo ?> = MutableStateFlow (OC_FILE_WITH_SYNC_INFO )
4850 private var currentFileAvailableOffline: MutableStateFlow <OCFileWithSyncInfo ?> = MutableStateFlow (OC_FILE_WITH_SYNC_INFO_AVAILABLE_OFFLINE )
4951
52+ @Rule
53+ @JvmField
54+ val retryFlakyTestUntilSuccessRule = RetryFlakyTestUntilSuccessRule ()
55+
5056 @Before
5157 fun setUp () {
5258 context = ApplicationProvider .getApplicationContext()
Original file line number Diff line number Diff line change 1+ package com.owncloud.android.utils
2+
3+ import android.util.Log
4+ import org.junit.rules.TestRule
5+ import org.junit.runner.Description
6+ import org.junit.runners.model.Statement
7+
8+ class RetryFlakyTestUntilSuccessRule (val count : Int = 3 ) : TestRule {
9+
10+ companion object {
11+ private const val TAG = " RetryFlakyTestUntilSuccessRule"
12+ }
13+
14+ override fun apply (base : Statement , description : Description ): Statement = statement(base, description)
15+
16+ private fun statement (base : Statement , description : Description ): Statement {
17+ return object : Statement () {
18+ @Throws(Throwable ::class )
19+ override fun evaluate () {
20+ var throwable: Throwable ? = null
21+ val displayName = description.displayName
22+ for (i in 1 until count + 1 ) {
23+ try {
24+ Log .i(TAG , " $displayName : Run $i " )
25+ base.evaluate()
26+ return
27+ } catch (t: Throwable ) {
28+ throwable = t
29+ Log .e(TAG , " $displayName : Run $i failed." )
30+ }
31+ }
32+ Log .e(TAG , " $displayName : Giving up after run $count failures." )
33+ throw throwable!!
34+ }
35+ }
36+ }
37+ }
You can’t perform that action at this time.
0 commit comments