Something went wrong. Try again.
A fork of Simple Time Tracker with WearOS support. (Now integrated upstream)
Something went wrong. Try again.
SimpleTimeTracker-WearOS app src androidTest java com example util simpletimetracker utils RetryTestRule.kt
12345678910111213141516171819202122232425262728293031323334353637383940package com.example.util.simpletimetracker.utils
import android.util.Logimport org.junit.rules.TestRuleimport org.junit.runner.Descriptionimport org.junit.runners.model.Statement
/** * Retry test rule used to retry test that failed. */class RetryTestRule(val retryCount: Int = 5) : TestRule {
private val tag: String = 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
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!! } } }}