2
0
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:
Aaron Train 2022-01-04 15:17:02 -05:00 committed by GitHub
parent eb4c60fe9e
commit 8edd3f9fa1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 35 additions and 0 deletions

View File

@ -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()
}
}
}

View File

@ -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