File tree 2 files changed +43
-0
lines changed
owncloudApp/src/androidTest/java/com/owncloud/android
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
20
20
import com.owncloud.android.testutil.OC_FILE_WITH_SYNC_INFO_AND_WITHOUT_PERSONAL_SPACE
21
21
import com.owncloud.android.testutil.OC_FILE_WITH_SYNC_INFO_AVAILABLE_OFFLINE
22
22
import com.owncloud.android.utils.DisplayUtils
23
+ import com.owncloud.android.utils.RetryFlakyTestUntilSuccessRule
23
24
import com.owncloud.android.utils.matchers.assertVisibility
24
25
import com.owncloud.android.utils.matchers.isDisplayed
25
26
import com.owncloud.android.utils.matchers.withDrawable
@@ -29,6 +30,7 @@ import io.mockk.mockk
29
30
import kotlinx.coroutines.flow.MutableStateFlow
30
31
import org.junit.Before
31
32
import org.junit.Ignore
33
+ import org.junit.Rule
32
34
import org.junit.Test
33
35
import org.koin.androidx.viewmodel.dsl.viewModel
34
36
import org.koin.core.context.startKoin
@@ -47,6 +49,10 @@ class FileDetailsFragmentTest {
47
49
private var currentFileSyncInfo: MutableStateFlow <OCFileWithSyncInfo ?> = MutableStateFlow (OC_FILE_WITH_SYNC_INFO )
48
50
private var currentFileAvailableOffline: MutableStateFlow <OCFileWithSyncInfo ?> = MutableStateFlow (OC_FILE_WITH_SYNC_INFO_AVAILABLE_OFFLINE )
49
51
52
+ @Rule
53
+ @JvmField
54
+ val retryFlakyTestUntilSuccessRule = RetryFlakyTestUntilSuccessRule ()
55
+
50
56
@Before
51
57
fun setUp () {
52
58
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