Created
October 1, 2025 14:43
-
-
Save AaronMT/38f7572007063cf37cda9d4b8dac819d to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| import androidx.test.espresso.IdlingResourceTimeoutException | |
| import androidx.test.espresso.NoMatchingViewException | |
| import androidx.test.ext.junit.runners.AndroidJUnit4 | |
| import androidx.test.filters.LargeTest | |
| import androidx.test.uiautomator.UiObjectNotFoundException | |
| import junit.framework.AssertionFailedError | |
| import leakcanary.NoLeakAssertionFailedError | |
| import org.junit.Rule | |
| import org.junit.Test | |
| import org.junit.runner.RunWith | |
| import org.junit.runners.Parameterized | |
| import java.util.concurrent.atomic.AtomicInteger | |
| import kotlin.test.assertTrue | |
| @RunWith(Parameterized::class) | |
| @LargeTest | |
| class RetryRuleRetryableExceptionsTest( | |
| private val throwableSupplier: () -> Throwable | |
| ) { | |
| companion object { | |
| @JvmStatic | |
| @Parameterized.Parameters(name = "{index}: {0}") | |
| fun data(): Collection<Array<out Any>> = listOf( | |
| arrayOf({ AssertionError("Retryable AssertionError") as Throwable }), | |
| arrayOf({ AssertionFailedError("Retryable AssertionFailedError") as Throwable }), | |
| arrayOf({ UiObjectNotFoundException("Retryable UiObjectNotFoundException") as Throwable }), | |
| arrayOf({ NoMatchingViewException.Builder().withViewDescription("Retryable NoMatchingViewException").build() as Throwable }), | |
| arrayOf({ IdlingResourceTimeoutException("Retryable IdlingResourceTimeoutException") as Throwable }), | |
| arrayOf({ RuntimeException("Retryable RuntimeException") as Throwable }), | |
| arrayOf({ NullPointerException("Retryable NullPointerException") as Throwable }) | |
| ) | |
| } | |
| @get:Rule | |
| val retryRule = RetryTestRule(retryCount = 2) | |
| @Test | |
| fun testRetryableExceptionsAreRetried() { | |
| val attempts = AtomicInteger(0) | |
| if (attempts.incrementAndGet() < 2) { | |
| throw throwableSupplier.invoke() | |
| } | |
| // If we reach here, it means the retry worked. | |
| assertTrue(true, "Test retried and passed on attempt=${attempts.get()}") | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment