[[["わかりやすい","easyToUnderstand","thumb-up"],["問題の解決に役立った","solvedMyProblem","thumb-up"],["その他","otherUp","thumb-up"]],[["必要な情報がない","missingTheInformationINeed","thumb-down"],["複雑すぎる / 手順が多すぎる","tooComplicatedTooManySteps","thumb-down"],["最新ではない","outOfDate","thumb-down"],["翻訳に関する問題","translationIssue","thumb-down"],["サンプル / コードに問題がある","samplesCodeIssue","thumb-down"],["その他","otherDown","thumb-down"]],["最終更新日 2025-03-26 UTC。"],[],[],null,["# Automatic test retry\n\nA test might fail for any reason, and sometimes simply re-running the test is\nenough to make it pass again (due to flakiness, such as from issues in the\nunderlying infrastructure). You can configure Tradefed to conduct the retry\nautomatically.\n\nThe core of auto-retry is to avoid re-running **all** of the tests; it re-runs\nonly the failed tests, resulting in large savings in execution time.\n\nTradefed also supports running tests multiple times in order to detect\nflakiness via the **iterations** feature. In this case, all tests will be\nre-run, and the test will fail if any of the iterations fail.\n\nEnable automatic retry\n----------------------\n\nThe automatic retry is controlled via the\n[RetryDecision object](https://android.googlesource.com/platform/tools/tradefederation/+/android16-release/src/com/android/tradefed/retry/BaseRetryDecision.java)\nwhich provides two options to enable the feature: `max-testcase-run-count`\nand `retry-strategy`.\n\n`max-testcase-run-count` drives the number of retries or iterations that will\nbe attempted. It sets an upper bound to avoid retrying forever.\n`retry-strategy` drives the decision of how to retry; see the following sections\nfor more details.\n\nDisable automatic retry\n-----------------------\n\nUse the following option: \n\n --retry-strategy NO_RETRY\n\nRetry failures\n--------------\n\nTo retry test failures, use the following options: \n\n --retry-strategy RETRY_ANY_FAILURE --max-testcase-run-count X\n\nThis will retry the failure until it passes or until the max number of retries\nis reached, whichever comes first.\n| **Note:** `max-testcase-run-count` counts the number of run attempts, meaning in case of a crash, it is possible for a test case to not have been executed `max-testcase-run-count` times.\n\nIterations\n----------\n\nTo re-run tests for a number of time, the following options can be used: \n\n --retry-strategy ITERATIONS --max-testcase-run-count X\n\nWhat do the results look like?\n------------------------------\n\nResult reporters by default will receive aggregated results of all attempts.\n\nFor example: a `Fail` and a `Pass` for `RETRY_ANY_FAILURE` will result in an\naggregated `Pass` since the retry managed to clear the failure.\n\nIt is possible for reporters to receive the non-aggregated results. To do so,\nthey need to extend the\n[ISupportGranularResults interface](https://android.googlesource.com/platform/tools/tradefederation/+/android16-release/invocation_interfaces/com/android/tradefed/result/retry/ISupportGranularResults.java)\nthat declares support for the granular (non-aggregated) results.\n\nImplementation details\n----------------------\n\nTo enable auto-retry to rerun failures at the test case level, implement\n[ITestFilterReceiver](/reference/tradefed/com/android/tradefed/testtype/ITestFilterReceiver).\n\nIf you can't implement ITestFilterReceiver, you can implement\n[IAutoRetriableTest](https://android.googlesource.com/platform/tools/tradefederation/+/refs/heads/android16-release/src/com/android/tradefed/testtype/retry/IAutoRetriableTest.java)\nto manually control how rerun operates.\n[InstalledInstrumentationsTest](https://android.googlesource.com/platform/tools/tradefederation/+/refs/heads/android16-release/test_framework/com/android/tradefed/testtype/InstalledInstrumentationsTest.java)\nis an example implementation of that interface."]]