-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
10b7fd5
commit 6139073
Showing
4 changed files
with
60 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
45 changes: 45 additions & 0 deletions
45
app/src/androidTest/java/com/onfido/evergreen/RetryTestRule.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package com.onfido.evergreen | ||
|
||
import android.util.Log | ||
import org.junit.rules.TestRule | ||
import org.junit.runner.Description | ||
import org.junit.runners.model.Statement | ||
|
||
/** | ||
* Retry test rule used to retry test that failed. | ||
* Retry failed test 3 times | ||
*/ | ||
class RetryTestRule(val retryCount: Int = 3) : TestRule { | ||
|
||
private val TAG = RetryTestRule::class.java.simpleName | ||
|
||
override fun apply(base: Statement, description: Description): Statement { | ||
return statement(base, description) | ||
} | ||
|
||
private fun statement(base: Statement, description: Description): Statement { | ||
return object : Statement() { | ||
@Throws(Throwable::class) | ||
override fun evaluate() { | ||
var caughtThrowable: Throwable? = null | ||
|
||
// implement retry logic here | ||
for (i in 0 until retryCount) { | ||
try { | ||
base.evaluate() | ||
return | ||
} catch (t: Throwable) { | ||
caughtThrowable = t | ||
Log.e(TAG, description.displayName + ": run " + (i + 1) + " failed") | ||
} | ||
} | ||
|
||
Log.e( | ||
TAG, | ||
description.displayName + ": giving up after " + retryCount + " failures" | ||
) | ||
throw caughtThrowable!! | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters