mirror of
https://github.com/fork-maintainers/iceraven-browser
synced 2024-11-05 21:20:45 +00:00
No issue: Try out RetryTestRule in SmokeTest UI test class (#22868)
* Add RetryTestRule to SmokeTest UI tests * fix: newline in RetryTestRule.kt fix: switch off generic Throwable Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
This commit is contained in:
parent
eb4c60fe9e
commit
8edd3f9fa1
@ -0,0 +1,30 @@
|
||||
package org.mozilla.fenix.helpers
|
||||
|
||||
import org.junit.rules.TestRule
|
||||
import org.junit.runner.Description
|
||||
import org.junit.runners.model.Statement
|
||||
import java.lang.AssertionError
|
||||
|
||||
class RetryTestRule(private val retryCount: Int = 5) : TestRule {
|
||||
|
||||
override fun apply(base: Statement, description: Description): Statement {
|
||||
return statement {
|
||||
for (i in 1..retryCount) {
|
||||
try {
|
||||
base.evaluate()
|
||||
break
|
||||
} catch (t: AssertionError) {
|
||||
if (i == retryCount) {
|
||||
throw t
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private inline fun statement(crossinline eval: () -> Unit): Statement {
|
||||
return object : Statement() {
|
||||
override fun evaluate() = eval()
|
||||
}
|
||||
}
|
||||
}
|
@ -30,6 +30,7 @@ import org.mozilla.fenix.helpers.Constants.PackageName.YOUTUBE_APP
|
||||
import org.mozilla.fenix.helpers.FeatureSettingsHelper
|
||||
import org.mozilla.fenix.helpers.HomeActivityIntentTestRule
|
||||
import org.mozilla.fenix.helpers.RecyclerViewIdlingResource
|
||||
import org.mozilla.fenix.helpers.RetryTestRule
|
||||
import org.mozilla.fenix.helpers.TestAssetHelper
|
||||
import org.mozilla.fenix.helpers.TestAssetHelper.downloadFileName
|
||||
import org.mozilla.fenix.helpers.TestHelper
|
||||
@ -97,6 +98,10 @@ class SmokeTest {
|
||||
android.Manifest.permission.READ_EXTERNAL_STORAGE
|
||||
)
|
||||
|
||||
@Rule
|
||||
@JvmField
|
||||
val retryTestRule = RetryTestRule(3)
|
||||
|
||||
@Before
|
||||
fun setUp() {
|
||||
// Initializing this as part of class construction, below the rule would throw a NPE
|
||||
|
Loading…
Reference in New Issue
Block a user