From 8d3b4d28993d3275cf82b7056afbe5e4d28a17d1 Mon Sep 17 00:00:00 2001 From: David Allison <62114487+david-allison@users.noreply.github.com> Date: Fri, 2 Feb 2024 02:04:28 +0000 Subject: [PATCH] fix: emulator tests (apply @Flaky) `IgnoreFlakyTestsInCIRule` was not applied to the test class So we apply the rule, and improve the documentation --- .../java/com/ichi2/anki/tests/InstrumentedTest.kt | 5 +++++ .../com/ichi2/testutils/IgnoreFlakyTestsInCIRule.kt | 10 ++++++++++ 2 files changed, 15 insertions(+) diff --git a/AnkiDroid/src/androidTest/java/com/ichi2/anki/tests/InstrumentedTest.kt b/AnkiDroid/src/androidTest/java/com/ichi2/anki/tests/InstrumentedTest.kt index f8fe7bfae13d..4b5fa18de754 100644 --- a/AnkiDroid/src/androidTest/java/com/ichi2/anki/tests/InstrumentedTest.kt +++ b/AnkiDroid/src/androidTest/java/com/ichi2/anki/tests/InstrumentedTest.kt @@ -33,6 +33,7 @@ import com.ichi2.libanki.Collection import com.ichi2.libanki.Consts import com.ichi2.libanki.Note import com.ichi2.libanki.utils.TimeManager +import com.ichi2.testutils.IgnoreFlakyTestsInCIRule import kotlinx.coroutines.runBlocking import net.ankiweb.rsdroid.BackendException import org.junit.After @@ -55,6 +56,10 @@ abstract class InstrumentedTest { @get:Rule val ensureAllFilesAccessRule = EnsureAllFilesAccessRule() + /** Allows [com.ichi2.testutils.Flaky] to annotate tests in subclasses */ + @get:Rule + val ignoreFlakyTests = IgnoreFlakyTestsInCIRule() + /** * @return A File object pointing to a directory in which temporary test files can be placed. The directory is * emptied on every invocation of this method so it is suitable to use at the start of each test. diff --git a/testlib/src/main/java/com/ichi2/testutils/IgnoreFlakyTestsInCIRule.kt b/testlib/src/main/java/com/ichi2/testutils/IgnoreFlakyTestsInCIRule.kt index 17d7bdd0b6e4..f1e358e91f0d 100644 --- a/testlib/src/main/java/com/ichi2/testutils/IgnoreFlakyTestsInCIRule.kt +++ b/testlib/src/main/java/com/ichi2/testutils/IgnoreFlakyTestsInCIRule.kt @@ -30,6 +30,16 @@ import java.util.* /** * An annotation which marks a test as flaky so it will be skipped if run under CI + * + * The test class or a subclass must contain the code: + * + * ```kotlin + * @get:Rule + * val ignoreFlakyTests = IgnoreFlakyTestsInCIRule() + * ``` + * + * @see IgnoreFlakyTestsInCIRule + * * @param os The OS The test fails under (required) * @param message The message to display when the test is skipped */