How can I use @FlakyTest annotation now?

I am trying to run an unstable test with an espresso framework (and with Junit4) on Android Studio.

I want to establish how many times this should be repeated. Before i can use

@FlakyTest (tolerance = 5)

// (e.g. number 5 to repeat)

But this annotation is deprecated at API level 24. - (link to android.developers.com)

A new @FlakyTest annotation is now available - no tolerance variable. (link to android.developers.com)

I need to establish how many times the test can be repeated, but I do not know how to do it. Any idea?

+7
source share
2

, . , .

, . .

, - . , , . :

android {
    defaultConfig {
        testInstrumentationRunnerArgument "notAnnotation", "android.support.test.filters.FlakyTest"
    }
}

.

+5

https://gist.github.com/abyx/897229#gistcomment-2851489

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() {

            override fun evaluate() {
                Log.e(TAG, "Evaluating ${description.methodName}")

                var caughtThrowable: Throwable? = null

                for (i in 0 until retryCount) {
                    try {
                        base.evaluate()
                        return
                    } catch (t: Throwable) {
                        caughtThrowable = t
                        Log.e(TAG, description.methodName + ": run " + (i + 1) + " failed")
                    }
                }

                Log.e(TAG, description.methodName + ": giving up after " + retryCount + " failures")
                if (caughtThrowable != null)
                    throw caughtThrowable
            }
        }
    }
}

,

@Rule
@JvmField
val mRetryTestRule = RetryTestRule()
0

Source: https://habr.com/ru/post/1683532/


All Articles