Repository: android/testing-samples Branch: main Commit: 8c9df3a534ef Files: 577 Total size: 923.0 KB Directory structure: gitextract_2qqpyglt/ ├── .bazelrc ├── .github/ │ ├── ci-gradle.properties │ └── workflows/ │ ├── composescreenshot.yml │ ├── copy-branch.yml │ ├── gradle-wrapper-validation.yml │ └── test-all.yml ├── .gitignore ├── BUILD.bazel ├── CODEOWNERS ├── CONTRIBUTING.md ├── LICENSE ├── README.md ├── WORKSPACE ├── bazelci/ │ └── buildkite-pipeline.yml ├── common_defs.bzl ├── integration/ │ └── ServiceTestRuleSample/ │ ├── .gitignore │ ├── README.md │ ├── app/ │ │ ├── build.gradle │ │ └── src/ │ │ ├── androidTest/ │ │ │ └── java/ │ │ │ └── com/ │ │ │ └── example/ │ │ │ └── android/ │ │ │ └── testing/ │ │ │ └── ServiceTestRuleSample/ │ │ │ └── LocalServiceTest.java │ │ └── main/ │ │ ├── AndroidManifest.xml │ │ ├── java/ │ │ │ └── com/ │ │ │ └── example/ │ │ │ └── android/ │ │ │ └── testing/ │ │ │ └── ServiceTestRuleSample/ │ │ │ └── LocalService.java │ │ └── res/ │ │ ├── values/ │ │ │ ├── strings.xml │ │ │ └── styles.xml │ │ ├── values-v13/ │ │ │ └── styles.xml │ │ └── values-v21/ │ │ └── styles.xml │ ├── build.gradle │ ├── gradle/ │ │ └── wrapper/ │ │ ├── gradle-wrapper.jar │ │ └── gradle-wrapper.properties │ ├── gradle.properties │ ├── gradlew │ ├── gradlew.bat │ └── settings.gradle ├── projects.conf ├── renovate.json ├── runner/ │ ├── AndroidJunitRunnerSample/ │ │ ├── .gitignore │ │ ├── README.md │ │ ├── app/ │ │ │ ├── build.gradle │ │ │ └── src/ │ │ │ ├── androidTest/ │ │ │ │ └── java/ │ │ │ │ └── com/ │ │ │ │ └── example/ │ │ │ │ └── android/ │ │ │ │ └── testing/ │ │ │ │ └── androidjunitrunnersample/ │ │ │ │ ├── CalculatorAddParameterizedTest.java │ │ │ │ ├── CalculatorInstrumentationTest.java │ │ │ │ ├── CalculatorTest.java │ │ │ │ ├── HintMatcher.java │ │ │ │ ├── OperationHintInstrumentationTest.java │ │ │ │ ├── OperationHintLegacyInstrumentationTest.java │ │ │ │ └── suite/ │ │ │ │ ├── AndroidTestSuite.java │ │ │ │ ├── InstrumentationTestSuite.java │ │ │ │ └── UnitTestSuite.java │ │ │ └── main/ │ │ │ ├── AndroidManifest.xml │ │ │ ├── java/ │ │ │ │ └── com/ │ │ │ │ └── example/ │ │ │ │ └── android/ │ │ │ │ └── testing/ │ │ │ │ └── androidjunitrunnersample/ │ │ │ │ ├── Calculator.java │ │ │ │ └── CalculatorActivity.java │ │ │ └── res/ │ │ │ ├── layout/ │ │ │ │ └── activity_calculator.xml │ │ │ ├── values/ │ │ │ │ ├── dimens.xml │ │ │ │ ├── strings.xml │ │ │ │ └── styles.xml │ │ │ ├── values-v14/ │ │ │ │ └── styles.xml │ │ │ ├── values-v21/ │ │ │ │ └── styles.xml │ │ │ └── values-w820dp/ │ │ │ └── dimens.xml │ │ ├── build.gradle │ │ ├── gradle/ │ │ │ └── wrapper/ │ │ │ ├── gradle-wrapper.jar │ │ │ └── gradle-wrapper.properties │ │ ├── gradle.properties │ │ ├── gradlew │ │ ├── gradlew.bat │ │ └── settings.gradle │ ├── AndroidTestOrchestratorSample/ │ │ ├── .gitignore │ │ ├── README.md │ │ ├── app/ │ │ │ ├── build.gradle │ │ │ └── src/ │ │ │ ├── androidTest/ │ │ │ │ └── java/ │ │ │ │ └── com/ │ │ │ │ └── example/ │ │ │ │ └── android/ │ │ │ │ └── testing/ │ │ │ │ └── androidtestorchestratorsample/ │ │ │ │ ├── CalculatorAddParameterizedTest.java │ │ │ │ └── CalculatorInstrumentationTest.java │ │ │ └── main/ │ │ │ ├── AndroidManifest.xml │ │ │ ├── java/ │ │ │ │ └── com/ │ │ │ │ └── example/ │ │ │ │ └── android/ │ │ │ │ └── testing/ │ │ │ │ └── androidtestorchestratorsample/ │ │ │ │ ├── Calculator.java │ │ │ │ └── CalculatorActivity.java │ │ │ └── res/ │ │ │ ├── layout/ │ │ │ │ └── activity_calculator.xml │ │ │ ├── values/ │ │ │ │ ├── dimens.xml │ │ │ │ ├── strings.xml │ │ │ │ └── styles.xml │ │ │ ├── values-v14/ │ │ │ │ └── styles.xml │ │ │ ├── values-v21/ │ │ │ │ └── styles.xml │ │ │ └── values-w820dp/ │ │ │ └── dimens.xml │ │ ├── build.gradle │ │ ├── gradle/ │ │ │ └── wrapper/ │ │ │ ├── gradle-wrapper.jar │ │ │ └── gradle-wrapper.properties │ │ ├── gradle.properties │ │ ├── gradlew │ │ ├── gradlew.bat │ │ └── settings.gradle │ └── AndroidTestOrchestratorWithTestCoverageSample/ │ ├── .gitignore │ ├── README.md │ ├── app/ │ │ ├── build.gradle │ │ └── src/ │ │ ├── androidTest/ │ │ │ └── java/ │ │ │ └── com/ │ │ │ └── example/ │ │ │ └── android/ │ │ │ └── testing/ │ │ │ └── androidtestorchestratorsample/ │ │ │ ├── CalculatorAddParameterizedTest.java │ │ │ └── CalculatorInstrumentationTest.java │ │ └── main/ │ │ ├── AndroidManifest.xml │ │ ├── java/ │ │ │ └── com/ │ │ │ └── example/ │ │ │ └── android/ │ │ │ └── testing/ │ │ │ └── androidtestorchestratorsample/ │ │ │ ├── Calculator.java │ │ │ └── CalculatorActivity.java │ │ └── res/ │ │ ├── layout/ │ │ │ └── activity_calculator.xml │ │ ├── values/ │ │ │ ├── dimens.xml │ │ │ ├── strings.xml │ │ │ └── styles.xml │ │ ├── values-v14/ │ │ │ └── styles.xml │ │ ├── values-v21/ │ │ │ └── styles.xml │ │ └── values-w820dp/ │ │ └── dimens.xml │ ├── build.gradle │ ├── gradle/ │ │ └── wrapper/ │ │ ├── gradle-wrapper.jar │ │ └── gradle-wrapper.properties │ ├── gradle.properties │ ├── gradlew │ ├── gradlew.bat │ └── settings.gradle ├── test_all.sh ├── ui/ │ ├── PreviewScreenshot/ │ │ ├── .gitignore │ │ ├── README.md │ │ ├── app/ │ │ │ ├── .gitignore │ │ │ ├── build.gradle.kts │ │ │ ├── proguard-rules.pro │ │ │ └── src/ │ │ │ ├── main/ │ │ │ │ ├── AndroidManifest.xml │ │ │ │ ├── java/ │ │ │ │ │ └── com/ │ │ │ │ │ └── example/ │ │ │ │ │ └── compose/ │ │ │ │ │ └── previewscreenshot/ │ │ │ │ │ ├── MainActivity.kt │ │ │ │ │ └── ui/ │ │ │ │ │ └── theme/ │ │ │ │ │ ├── Color.kt │ │ │ │ │ ├── Theme.kt │ │ │ │ │ └── Type.kt │ │ │ │ └── res/ │ │ │ │ ├── drawable/ │ │ │ │ │ ├── ic_launcher_background.xml │ │ │ │ │ └── ic_launcher_foreground.xml │ │ │ │ ├── mipmap-anydpi-v26/ │ │ │ │ │ ├── ic_launcher.xml │ │ │ │ │ └── ic_launcher_round.xml │ │ │ │ ├── values/ │ │ │ │ │ ├── colors.xml │ │ │ │ │ ├── strings.xml │ │ │ │ │ └── themes.xml │ │ │ │ ├── values-es/ │ │ │ │ │ └── strings.xml │ │ │ │ └── xml/ │ │ │ │ ├── backup_rules.xml │ │ │ │ └── data_extraction_rules.xml │ │ │ └── screenshotTest/ │ │ │ └── kotlin/ │ │ │ └── com/ │ │ │ └── example/ │ │ │ └── compose/ │ │ │ └── previewscreenshot/ │ │ │ └── MainScreen.kt │ │ ├── build.gradle.kts │ │ ├── gradle/ │ │ │ ├── libs.versions.toml │ │ │ └── wrapper/ │ │ │ ├── gradle-wrapper.jar │ │ │ └── gradle-wrapper.properties │ │ ├── gradle.properties │ │ ├── gradlew │ │ ├── gradlew.bat │ │ └── settings.gradle.kts │ ├── espresso/ │ │ ├── AccessibilitySample/ │ │ │ ├── .gitignore │ │ │ ├── BUILD.bazel │ │ │ ├── README.md │ │ │ ├── app/ │ │ │ │ ├── build.gradle │ │ │ │ └── src/ │ │ │ │ ├── androidTest/ │ │ │ │ │ ├── AndroidManifest.xml │ │ │ │ │ └── java/ │ │ │ │ │ └── com/ │ │ │ │ │ └── example/ │ │ │ │ │ └── android/ │ │ │ │ │ └── testing/ │ │ │ │ │ └── espresso/ │ │ │ │ │ └── AccessibilitySample/ │ │ │ │ │ └── AccessibilityChecksTest.java │ │ │ │ └── main/ │ │ │ │ ├── AndroidManifest.xml │ │ │ │ ├── AppManifest.xml │ │ │ │ ├── java/ │ │ │ │ │ └── com/ │ │ │ │ │ └── example/ │ │ │ │ │ └── android/ │ │ │ │ │ └── testing/ │ │ │ │ │ └── espresso/ │ │ │ │ │ └── AccessibilitySample/ │ │ │ │ │ └── MainActivity.java │ │ │ │ └── res/ │ │ │ │ ├── layout/ │ │ │ │ │ └── activity_main.xml │ │ │ │ ├── values/ │ │ │ │ │ ├── dimens.xml │ │ │ │ │ ├── strings.xml │ │ │ │ │ └── styles.xml │ │ │ │ ├── values-v13/ │ │ │ │ │ └── styles.xml │ │ │ │ ├── values-v21/ │ │ │ │ │ └── styles.xml │ │ │ │ └── values-w820dp/ │ │ │ │ └── dimens.xml │ │ │ ├── build.gradle │ │ │ ├── gradle/ │ │ │ │ └── wrapper/ │ │ │ │ ├── gradle-wrapper.jar │ │ │ │ └── gradle-wrapper.properties │ │ │ ├── gradle.properties │ │ │ ├── gradlew │ │ │ ├── gradlew.bat │ │ │ └── settings.gradle │ │ ├── BasicSample/ │ │ │ ├── .gitignore │ │ │ ├── BUILD.bazel │ │ │ ├── README.md │ │ │ ├── app/ │ │ │ │ ├── build.gradle │ │ │ │ └── src/ │ │ │ │ ├── androidTest/ │ │ │ │ │ ├── AndroidManifest.xml │ │ │ │ │ └── java/ │ │ │ │ │ └── com/ │ │ │ │ │ └── example/ │ │ │ │ │ └── android/ │ │ │ │ │ └── testing/ │ │ │ │ │ └── espresso/ │ │ │ │ │ └── BasicSample/ │ │ │ │ │ ├── ChangeTextBehaviorKtTest.kt │ │ │ │ │ └── ChangeTextBehaviorTest.java │ │ │ │ ├── main/ │ │ │ │ │ ├── AndroidManifest.xml │ │ │ │ │ ├── AppManifest.xml │ │ │ │ │ ├── java/ │ │ │ │ │ │ └── com/ │ │ │ │ │ │ └── example/ │ │ │ │ │ │ └── android/ │ │ │ │ │ │ └── testing/ │ │ │ │ │ │ └── espresso/ │ │ │ │ │ │ └── BasicSample/ │ │ │ │ │ │ ├── MainActivity.java │ │ │ │ │ │ └── ShowTextActivity.java │ │ │ │ │ └── res/ │ │ │ │ │ ├── layout/ │ │ │ │ │ │ ├── activity_main.xml │ │ │ │ │ │ └── activity_show_text.xml │ │ │ │ │ ├── values/ │ │ │ │ │ │ ├── dimens.xml │ │ │ │ │ │ ├── strings.xml │ │ │ │ │ │ └── styles.xml │ │ │ │ │ ├── values-v13/ │ │ │ │ │ │ └── styles.xml │ │ │ │ │ ├── values-v21/ │ │ │ │ │ │ └── styles.xml │ │ │ │ │ └── values-w820dp/ │ │ │ │ │ └── dimens.xml │ │ │ │ └── test/ │ │ │ │ └── java/ │ │ │ │ └── com/ │ │ │ │ └── example/ │ │ │ │ └── android/ │ │ │ │ └── testing/ │ │ │ │ └── espresso/ │ │ │ │ └── BasicSample/ │ │ │ │ └── ChangeTextBehaviorLocalTest.java │ │ │ ├── build.gradle │ │ │ ├── gradle/ │ │ │ │ └── wrapper/ │ │ │ │ ├── gradle-wrapper.jar │ │ │ │ └── gradle-wrapper.properties │ │ │ ├── gradle.properties │ │ │ ├── gradlew │ │ │ ├── gradlew.bat │ │ │ └── settings.gradle │ │ ├── CustomMatcherSample/ │ │ │ ├── .gitignore │ │ │ ├── BUILD.bazel │ │ │ ├── README.md │ │ │ ├── app/ │ │ │ │ ├── build.gradle │ │ │ │ └── src/ │ │ │ │ ├── androidTest/ │ │ │ │ │ └── AndroidManifest.xml │ │ │ │ ├── main/ │ │ │ │ │ ├── AndroidManifest.xml │ │ │ │ │ ├── AppManifest.xml │ │ │ │ │ ├── java/ │ │ │ │ │ │ └── com/ │ │ │ │ │ │ └── example/ │ │ │ │ │ │ └── android/ │ │ │ │ │ │ └── testing/ │ │ │ │ │ │ └── espresso/ │ │ │ │ │ │ └── CustomMatcherSample/ │ │ │ │ │ │ └── MainActivity.java │ │ │ │ │ └── res/ │ │ │ │ │ ├── drawable/ │ │ │ │ │ │ ├── correct.xml │ │ │ │ │ │ └── incorrect.xml │ │ │ │ │ ├── layout/ │ │ │ │ │ │ └── activity_main.xml │ │ │ │ │ ├── values/ │ │ │ │ │ │ ├── dimens.xml │ │ │ │ │ │ ├── strings.xml │ │ │ │ │ │ └── styles.xml │ │ │ │ │ ├── values-v13/ │ │ │ │ │ │ └── styles.xml │ │ │ │ │ ├── values-v21/ │ │ │ │ │ │ └── styles.xml │ │ │ │ │ └── values-w820dp/ │ │ │ │ │ └── dimens.xml │ │ │ │ └── sharedTest/ │ │ │ │ └── java/ │ │ │ │ └── com/ │ │ │ │ └── example/ │ │ │ │ └── android/ │ │ │ │ └── testing/ │ │ │ │ └── espresso/ │ │ │ │ └── CustomMatcherSample/ │ │ │ │ ├── HintMatcher.java │ │ │ │ └── HintMatchersTest.java │ │ │ ├── build.gradle │ │ │ ├── gradle/ │ │ │ │ └── wrapper/ │ │ │ │ ├── gradle-wrapper.jar │ │ │ │ └── gradle-wrapper.properties │ │ │ ├── gradle.properties │ │ │ ├── gradlew │ │ │ ├── gradlew.bat │ │ │ └── settings.gradle │ │ ├── DataAdapterSample/ │ │ │ ├── .gitignore │ │ │ ├── BUILD.bazel │ │ │ ├── README.md │ │ │ ├── app/ │ │ │ │ ├── build.gradle │ │ │ │ └── src/ │ │ │ │ ├── androidTest/ │ │ │ │ │ └── AndroidManifest.xml │ │ │ │ ├── main/ │ │ │ │ │ ├── AndroidManifest.xml │ │ │ │ │ ├── AppManifest.xml │ │ │ │ │ ├── java/ │ │ │ │ │ │ └── com/ │ │ │ │ │ │ └── example/ │ │ │ │ │ │ └── android/ │ │ │ │ │ │ └── testing/ │ │ │ │ │ │ └── espresso/ │ │ │ │ │ │ └── DataAdapterSample/ │ │ │ │ │ │ └── LongListActivity.java │ │ │ │ │ └── res/ │ │ │ │ │ ├── layout/ │ │ │ │ │ │ ├── list_activity.xml │ │ │ │ │ │ └── list_item.xml │ │ │ │ │ ├── values/ │ │ │ │ │ │ ├── dimens.xml │ │ │ │ │ │ ├── strings.xml │ │ │ │ │ │ └── styles.xml │ │ │ │ │ ├── values-v21/ │ │ │ │ │ │ └── styles.xml │ │ │ │ │ └── values-w820dp/ │ │ │ │ │ └── dimens.xml │ │ │ │ └── sharedTest/ │ │ │ │ └── java/ │ │ │ │ └── com/ │ │ │ │ └── example/ │ │ │ │ └── android/ │ │ │ │ └── testing/ │ │ │ │ └── espresso/ │ │ │ │ └── DataAdapterSample/ │ │ │ │ └── LongListActivityTest.java │ │ │ ├── build.gradle │ │ │ ├── gradle/ │ │ │ │ └── wrapper/ │ │ │ │ ├── gradle-wrapper.jar │ │ │ │ └── gradle-wrapper.properties │ │ │ ├── gradle.properties │ │ │ ├── gradlew │ │ │ ├── gradlew.bat │ │ │ └── settings.gradle │ │ ├── EspressoDeviceSample/ │ │ │ ├── .gitignore │ │ │ ├── BUILD.bazel │ │ │ ├── README.md │ │ │ ├── app/ │ │ │ │ ├── build.gradle │ │ │ │ └── src/ │ │ │ │ ├── androidTest/ │ │ │ │ │ ├── AndroidManifest.xml │ │ │ │ │ └── java/ │ │ │ │ │ └── com/ │ │ │ │ │ └── example/ │ │ │ │ │ └── android/ │ │ │ │ │ └── testing/ │ │ │ │ │ └── espresso/ │ │ │ │ │ └── EspressoDeviceSample/ │ │ │ │ │ ├── RequiresDisplayTest.kt │ │ │ │ │ └── ResizeDisplayTest.kt │ │ │ │ └── main/ │ │ │ │ ├── AndroidManifest.xml │ │ │ │ ├── AppManifest.xml │ │ │ │ ├── java/ │ │ │ │ │ └── com/ │ │ │ │ │ └── example/ │ │ │ │ │ └── android/ │ │ │ │ │ └── testing/ │ │ │ │ │ └── espresso/ │ │ │ │ │ └── EspressoDeviceSample/ │ │ │ │ │ └── MainActivity.java │ │ │ │ └── res/ │ │ │ │ ├── layout/ │ │ │ │ │ └── activity_main.xml │ │ │ │ ├── values/ │ │ │ │ │ ├── dimens.xml │ │ │ │ │ ├── strings.xml │ │ │ │ │ └── styles.xml │ │ │ │ ├── values-v13/ │ │ │ │ │ └── styles.xml │ │ │ │ ├── values-v21/ │ │ │ │ │ └── styles.xml │ │ │ │ └── values-w820dp/ │ │ │ │ └── dimens.xml │ │ │ ├── build.gradle │ │ │ ├── gradle/ │ │ │ │ └── wrapper/ │ │ │ │ ├── gradle-wrapper.jar │ │ │ │ └── gradle-wrapper.properties │ │ │ ├── gradle.properties │ │ │ ├── gradlew │ │ │ ├── gradlew.bat │ │ │ └── settings.gradle │ │ ├── FragmentScenarioSample/ │ │ │ ├── .gitignore │ │ │ ├── README.md │ │ │ ├── app/ │ │ │ │ ├── .gitignore │ │ │ │ ├── build.gradle │ │ │ │ ├── proguard-rules.pro │ │ │ │ └── src/ │ │ │ │ ├── main/ │ │ │ │ │ ├── AndroidManifest.xml │ │ │ │ │ ├── java/ │ │ │ │ │ │ └── com/ │ │ │ │ │ │ └── example/ │ │ │ │ │ │ └── android/ │ │ │ │ │ │ └── testing/ │ │ │ │ │ │ └── espresso/ │ │ │ │ │ │ └── fragmentscenario/ │ │ │ │ │ │ ├── SampleDialogFragment.kt │ │ │ │ │ │ └── SampleFragment.kt │ │ │ │ │ └── res/ │ │ │ │ │ ├── layout/ │ │ │ │ │ │ └── fragment_sample.xml │ │ │ │ │ └── values/ │ │ │ │ │ ├── colors.xml │ │ │ │ │ ├── strings.xml │ │ │ │ │ └── styles.xml │ │ │ │ └── sharedTest/ │ │ │ │ └── java/ │ │ │ │ └── com/ │ │ │ │ └── example/ │ │ │ │ └── android/ │ │ │ │ └── testing/ │ │ │ │ └── espresso/ │ │ │ │ └── fragmentscenario/ │ │ │ │ ├── SampleDialogFragmentTest.kt │ │ │ │ └── SampleFragmentTest.kt │ │ │ ├── build.gradle │ │ │ ├── gradle/ │ │ │ │ └── wrapper/ │ │ │ │ ├── gradle-wrapper.jar │ │ │ │ └── gradle-wrapper.properties │ │ │ ├── gradle.properties │ │ │ ├── gradlew │ │ │ ├── gradlew.bat │ │ │ └── settings.gradle │ │ ├── IdlingResourceSample/ │ │ │ ├── .gitignore │ │ │ ├── BUILD.bazel │ │ │ ├── README.md │ │ │ ├── app/ │ │ │ │ ├── build.gradle │ │ │ │ └── src/ │ │ │ │ ├── androidTest/ │ │ │ │ │ ├── AndroidManifest.xml │ │ │ │ │ └── java/ │ │ │ │ │ └── com/ │ │ │ │ │ └── example/ │ │ │ │ │ └── android/ │ │ │ │ │ └── testing/ │ │ │ │ │ └── espresso/ │ │ │ │ │ └── IdlingResourceSample/ │ │ │ │ │ └── ChangeTextBehaviorTest.java │ │ │ │ └── main/ │ │ │ │ ├── AndroidManifest.xml │ │ │ │ ├── AppManifest.xml │ │ │ │ ├── java/ │ │ │ │ │ └── com/ │ │ │ │ │ └── example/ │ │ │ │ │ └── android/ │ │ │ │ │ └── testing/ │ │ │ │ │ └── espresso/ │ │ │ │ │ └── IdlingResourceSample/ │ │ │ │ │ ├── IdlingResource/ │ │ │ │ │ │ └── SimpleIdlingResource.java │ │ │ │ │ ├── MainActivity.java │ │ │ │ │ └── MessageDelayer.java │ │ │ │ └── res/ │ │ │ │ ├── layout/ │ │ │ │ │ └── activity_main.xml │ │ │ │ ├── values/ │ │ │ │ │ ├── dimens.xml │ │ │ │ │ ├── strings.xml │ │ │ │ │ └── styles.xml │ │ │ │ ├── values-v13/ │ │ │ │ │ └── styles.xml │ │ │ │ ├── values-v21/ │ │ │ │ │ └── styles.xml │ │ │ │ └── values-w820dp/ │ │ │ │ └── dimens.xml │ │ │ ├── build.gradle │ │ │ ├── gradle/ │ │ │ │ └── wrapper/ │ │ │ │ ├── gradle-wrapper.jar │ │ │ │ └── gradle-wrapper.properties │ │ │ ├── gradle.properties │ │ │ ├── gradlew │ │ │ ├── gradlew.bat │ │ │ └── settings.gradle │ │ ├── IntentsAdvancedSample/ │ │ │ ├── BUILD.bazel │ │ │ ├── README.md │ │ │ ├── app/ │ │ │ │ ├── build.gradle │ │ │ │ └── src/ │ │ │ │ ├── androidTest/ │ │ │ │ │ ├── AndroidManifest.xml │ │ │ │ │ └── java/ │ │ │ │ │ └── com/ │ │ │ │ │ └── example/ │ │ │ │ │ └── android/ │ │ │ │ │ └── testing/ │ │ │ │ │ └── espresso/ │ │ │ │ │ └── intents/ │ │ │ │ │ └── AdvancedSample/ │ │ │ │ │ ├── ImageViewHasDrawableMatcher.java │ │ │ │ │ └── ImageViewerActivityTest.java │ │ │ │ └── main/ │ │ │ │ ├── AndroidManifest.xml │ │ │ │ ├── AppManifest.xml │ │ │ │ ├── java/ │ │ │ │ │ └── com/ │ │ │ │ │ └── example/ │ │ │ │ │ └── android/ │ │ │ │ │ └── testing/ │ │ │ │ │ └── espresso/ │ │ │ │ │ └── intents/ │ │ │ │ │ └── AdvancedSample/ │ │ │ │ │ └── ImageViewerActivity.java │ │ │ │ └── res/ │ │ │ │ ├── layout/ │ │ │ │ │ └── activity_image_viewer.xml │ │ │ │ ├── values/ │ │ │ │ │ ├── dimens.xml │ │ │ │ │ ├── strings.xml │ │ │ │ │ └── styles.xml │ │ │ │ ├── values-v13/ │ │ │ │ │ └── styles.xml │ │ │ │ ├── values-v21/ │ │ │ │ │ └── styles.xml │ │ │ │ └── values-w820dp/ │ │ │ │ └── dimens.xml │ │ │ ├── build.gradle │ │ │ ├── gradle/ │ │ │ │ └── wrapper/ │ │ │ │ ├── gradle-wrapper.jar │ │ │ │ └── gradle-wrapper.properties │ │ │ ├── gradle.properties │ │ │ ├── gradlew │ │ │ ├── gradlew.bat │ │ │ └── settings.gradle │ │ ├── IntentsBasicSample/ │ │ │ ├── BUILD.bazel │ │ │ ├── README.md │ │ │ ├── app/ │ │ │ │ ├── build.gradle │ │ │ │ └── src/ │ │ │ │ ├── androidTest/ │ │ │ │ │ └── AndroidManifest.xml │ │ │ │ ├── main/ │ │ │ │ │ ├── AndroidManifest.xml │ │ │ │ │ ├── AppManifest.xml │ │ │ │ │ ├── java/ │ │ │ │ │ │ └── com/ │ │ │ │ │ │ └── example/ │ │ │ │ │ │ └── android/ │ │ │ │ │ │ └── testing/ │ │ │ │ │ │ └── espresso/ │ │ │ │ │ │ └── IntentsBasicSample/ │ │ │ │ │ │ ├── ContactsActivity.java │ │ │ │ │ │ └── DialerActivity.java │ │ │ │ │ └── res/ │ │ │ │ │ ├── layout/ │ │ │ │ │ │ ├── activity_contacts.xml │ │ │ │ │ │ └── activity_dialer.xml │ │ │ │ │ ├── values/ │ │ │ │ │ │ ├── dimens.xml │ │ │ │ │ │ ├── strings.xml │ │ │ │ │ │ └── styles.xml │ │ │ │ │ ├── values-v13/ │ │ │ │ │ │ └── styles.xml │ │ │ │ │ ├── values-v21/ │ │ │ │ │ │ └── styles.xml │ │ │ │ │ └── values-w820dp/ │ │ │ │ │ └── dimens.xml │ │ │ │ └── sharedTest/ │ │ │ │ └── java/ │ │ │ │ └── com/ │ │ │ │ └── example/ │ │ │ │ └── android/ │ │ │ │ └── testing/ │ │ │ │ └── espresso/ │ │ │ │ └── IntentsBasicSample/ │ │ │ │ └── DialerActivityTest.java │ │ │ ├── build.gradle │ │ │ ├── gradle/ │ │ │ │ └── wrapper/ │ │ │ │ ├── gradle-wrapper.jar │ │ │ │ └── gradle-wrapper.properties │ │ │ ├── gradle.properties │ │ │ ├── gradlew │ │ │ ├── gradlew.bat │ │ │ └── settings.gradle │ │ ├── MultiProcessSample/ │ │ │ ├── .gitignore │ │ │ ├── README.md │ │ │ ├── app/ │ │ │ │ ├── .gitignore │ │ │ │ ├── build.gradle │ │ │ │ └── src/ │ │ │ │ ├── androidTest/ │ │ │ │ │ ├── AndroidManifest.xml │ │ │ │ │ └── java/ │ │ │ │ │ └── com/ │ │ │ │ │ └── example/ │ │ │ │ │ └── android/ │ │ │ │ │ └── testing/ │ │ │ │ │ └── espresso/ │ │ │ │ │ └── multiprocesssample/ │ │ │ │ │ └── ExampleInstrumentedTest.java │ │ │ │ └── main/ │ │ │ │ ├── AndroidManifest.xml │ │ │ │ ├── java/ │ │ │ │ │ └── com/ │ │ │ │ │ └── example/ │ │ │ │ │ └── android/ │ │ │ │ │ └── testing/ │ │ │ │ │ └── espresso/ │ │ │ │ │ └── multiprocesssample/ │ │ │ │ │ ├── DefaultProcessActivity.java │ │ │ │ │ ├── PrivateProcessActivity.java │ │ │ │ │ └── Util.java │ │ │ │ └── res/ │ │ │ │ ├── layout/ │ │ │ │ │ ├── activity_default_process.xml │ │ │ │ │ └── activity_private_process.xml │ │ │ │ └── values/ │ │ │ │ ├── colors.xml │ │ │ │ ├── strings.xml │ │ │ │ └── styles.xml │ │ │ ├── build.gradle │ │ │ ├── gradle/ │ │ │ │ └── wrapper/ │ │ │ │ ├── gradle-wrapper.jar │ │ │ │ └── gradle-wrapper.properties │ │ │ ├── gradle.properties │ │ │ ├── gradlew │ │ │ ├── gradlew.bat │ │ │ └── settings.gradle │ │ ├── MultiWindowSample/ │ │ │ ├── .gitignore │ │ │ ├── BUILD.bazel │ │ │ ├── README.md │ │ │ ├── app/ │ │ │ │ ├── build.gradle │ │ │ │ └── src/ │ │ │ │ ├── androidTest/ │ │ │ │ │ ├── AndroidManifest.xml │ │ │ │ │ └── java/ │ │ │ │ │ └── com/ │ │ │ │ │ └── example/ │ │ │ │ │ └── android/ │ │ │ │ │ └── testing/ │ │ │ │ │ └── espresso/ │ │ │ │ │ └── MultiWindowSample/ │ │ │ │ │ └── MultiWindowTest.java │ │ │ │ └── main/ │ │ │ │ ├── AndroidManifest.xml │ │ │ │ ├── AppManifest.xml │ │ │ │ ├── java/ │ │ │ │ │ └── com/ │ │ │ │ │ └── example/ │ │ │ │ │ └── android/ │ │ │ │ │ └── testing/ │ │ │ │ │ └── espresso/ │ │ │ │ │ └── MultiWindowSample/ │ │ │ │ │ └── SuggestActivity.java │ │ │ │ └── res/ │ │ │ │ ├── layout/ │ │ │ │ │ └── suggest_activity.xml │ │ │ │ └── values/ │ │ │ │ ├── strings.xml │ │ │ │ └── styles.xml │ │ │ ├── build.gradle │ │ │ ├── gradle/ │ │ │ │ └── wrapper/ │ │ │ │ ├── gradle-wrapper.jar │ │ │ │ └── gradle-wrapper.properties │ │ │ ├── gradle.properties │ │ │ ├── gradlew │ │ │ ├── gradlew.bat │ │ │ └── settings.gradle │ │ ├── RecyclerViewSample/ │ │ │ ├── .gitignore │ │ │ ├── BUILD.bazel │ │ │ ├── README.md │ │ │ ├── app/ │ │ │ │ ├── build.gradle │ │ │ │ └── src/ │ │ │ │ ├── androidTest/ │ │ │ │ │ ├── AndroidManifest.xml │ │ │ │ │ └── java/ │ │ │ │ │ └── com/ │ │ │ │ │ └── example/ │ │ │ │ │ └── android/ │ │ │ │ │ └── testing/ │ │ │ │ │ └── espresso/ │ │ │ │ │ └── RecyclerViewSample/ │ │ │ │ │ └── RecyclerViewSampleTest.java │ │ │ │ └── main/ │ │ │ │ ├── AndroidManifest.xml │ │ │ │ ├── AppManifest.xml │ │ │ │ ├── java/ │ │ │ │ │ └── com/ │ │ │ │ │ └── example/ │ │ │ │ │ └── android/ │ │ │ │ │ └── testing/ │ │ │ │ │ └── espresso/ │ │ │ │ │ └── RecyclerViewSample/ │ │ │ │ │ ├── CustomAdapter.java │ │ │ │ │ └── MainActivity.java │ │ │ │ └── res/ │ │ │ │ ├── layout/ │ │ │ │ │ ├── activity_main.xml │ │ │ │ │ └── text_row_item.xml │ │ │ │ ├── values/ │ │ │ │ │ ├── dimens.xml │ │ │ │ │ ├── strings.xml │ │ │ │ │ └── styles.xml │ │ │ │ ├── values-v13/ │ │ │ │ │ └── styles.xml │ │ │ │ ├── values-v21/ │ │ │ │ │ └── styles.xml │ │ │ │ └── values-w820dp/ │ │ │ │ └── dimens.xml │ │ │ ├── build.gradle │ │ │ ├── gradle/ │ │ │ │ └── wrapper/ │ │ │ │ ├── gradle-wrapper.jar │ │ │ │ └── gradle-wrapper.properties │ │ │ ├── gradle.properties │ │ │ ├── gradlew │ │ │ ├── gradlew.bat │ │ │ └── settings.gradle │ │ ├── ScreenshotSample/ │ │ │ ├── .gitignore │ │ │ ├── app/ │ │ │ │ ├── .gitignore │ │ │ │ ├── build.gradle │ │ │ │ ├── proguard-rules.pro │ │ │ │ └── src/ │ │ │ │ ├── androidTest/ │ │ │ │ │ └── java/ │ │ │ │ │ └── com/ │ │ │ │ │ └── example/ │ │ │ │ │ └── android/ │ │ │ │ │ └── testing/ │ │ │ │ │ └── espresso/ │ │ │ │ │ └── screenshotsample/ │ │ │ │ │ ├── ScreenshotJavaTest.java │ │ │ │ │ └── ScreenshotTest.kt │ │ │ │ └── main/ │ │ │ │ ├── AndroidManifest.xml │ │ │ │ ├── java/ │ │ │ │ │ └── com/ │ │ │ │ │ └── example/ │ │ │ │ │ └── android/ │ │ │ │ │ └── testing/ │ │ │ │ │ └── espresso/ │ │ │ │ │ └── screenshotsample/ │ │ │ │ │ └── MainActivity.kt │ │ │ │ └── res/ │ │ │ │ ├── drawable/ │ │ │ │ │ └── ic_launcher_background.xml │ │ │ │ ├── drawable-v24/ │ │ │ │ │ └── ic_launcher_foreground.xml │ │ │ │ ├── layout/ │ │ │ │ │ └── activity_main.xml │ │ │ │ ├── mipmap-anydpi-v26/ │ │ │ │ │ ├── ic_launcher.xml │ │ │ │ │ └── ic_launcher_round.xml │ │ │ │ ├── values/ │ │ │ │ │ ├── colors.xml │ │ │ │ │ ├── strings.xml │ │ │ │ │ └── themes.xml │ │ │ │ └── values-night/ │ │ │ │ └── themes.xml │ │ │ ├── build.gradle │ │ │ ├── gradle/ │ │ │ │ └── wrapper/ │ │ │ │ ├── gradle-wrapper.jar │ │ │ │ └── gradle-wrapper.properties │ │ │ ├── gradle.properties │ │ │ ├── gradlew │ │ │ ├── gradlew.bat │ │ │ └── settings.gradle │ │ └── WebBasicSample/ │ │ ├── .gitignore │ │ ├── README.md │ │ ├── app/ │ │ │ ├── build.gradle │ │ │ └── src/ │ │ │ ├── androidTest/ │ │ │ │ └── java/ │ │ │ │ └── com/ │ │ │ │ └── example/ │ │ │ │ └── android/ │ │ │ │ └── testing/ │ │ │ │ └── espresso/ │ │ │ │ └── web/ │ │ │ │ └── BasicSample/ │ │ │ │ └── WebViewActivityTest.java │ │ │ └── main/ │ │ │ ├── AndroidManifest.xml │ │ │ ├── assets/ │ │ │ │ ├── web_form.html │ │ │ │ └── web_form_response.html │ │ │ ├── java/ │ │ │ │ └── com/ │ │ │ │ └── example/ │ │ │ │ └── android/ │ │ │ │ └── testing/ │ │ │ │ └── espresso/ │ │ │ │ └── web/ │ │ │ │ └── BasicSample/ │ │ │ │ └── WebViewActivity.java │ │ │ └── res/ │ │ │ ├── layout/ │ │ │ │ └── activity_web_view.xml │ │ │ ├── values/ │ │ │ │ ├── dimens.xml │ │ │ │ ├── strings.xml │ │ │ │ └── styles.xml │ │ │ ├── values-v13/ │ │ │ │ └── styles.xml │ │ │ ├── values-v21/ │ │ │ │ └── styles.xml │ │ │ └── values-w820dp/ │ │ │ └── dimens.xml │ │ ├── build.gradle │ │ ├── gradle/ │ │ │ └── wrapper/ │ │ │ ├── gradle-wrapper.jar │ │ │ └── gradle-wrapper.properties │ │ ├── gradle.properties │ │ ├── gradlew │ │ ├── gradlew.bat │ │ └── settings.gradle │ └── uiautomator/ │ └── BasicSample/ │ ├── .gitignore │ ├── BUILD.bazel │ ├── README.md │ ├── app/ │ │ ├── build.gradle │ │ └── src/ │ │ ├── androidTest/ │ │ │ ├── AndroidManifest.xml │ │ │ └── java/ │ │ │ └── com/ │ │ │ └── example/ │ │ │ └── android/ │ │ │ └── testing/ │ │ │ └── uiautomator/ │ │ │ └── BasicSample/ │ │ │ └── ChangeTextBehaviorTest.java │ │ └── main/ │ │ ├── AndroidManifest.xml │ │ ├── AppManifest.xml │ │ ├── java/ │ │ │ └── com/ │ │ │ └── example/ │ │ │ └── android/ │ │ │ └── testing/ │ │ │ └── uiautomator/ │ │ │ └── BasicSample/ │ │ │ ├── MainActivity.java │ │ │ └── ShowTextActivity.java │ │ └── res/ │ │ ├── layout/ │ │ │ ├── activity_main.xml │ │ │ └── activity_show_text.xml │ │ ├── values/ │ │ │ ├── dimens.xml │ │ │ ├── strings.xml │ │ │ └── styles.xml │ │ ├── values-v13/ │ │ │ └── styles.xml │ │ ├── values-v21/ │ │ │ └── styles.xml │ │ └── values-w820dp/ │ │ └── dimens.xml │ ├── build.gradle │ ├── gradle/ │ │ └── wrapper/ │ │ ├── gradle-wrapper.jar │ │ └── gradle-wrapper.properties │ ├── gradle.properties │ ├── gradlew │ ├── gradlew.bat │ └── settings.gradle ├── unit/ │ ├── BasicNativeAndroidTest/ │ │ ├── .gitignore │ │ ├── README.md │ │ ├── app/ │ │ │ ├── .gitignore │ │ │ ├── build.gradle │ │ │ ├── proguard-rules.pro │ │ │ └── src/ │ │ │ ├── androidTest/ │ │ │ │ └── java/ │ │ │ │ └── com/ │ │ │ │ └── example/ │ │ │ │ └── android/ │ │ │ │ └── testing/ │ │ │ │ └── nativesample/ │ │ │ │ └── AdderTest.kt │ │ │ └── main/ │ │ │ ├── AndroidManifest.xml │ │ │ └── cpp/ │ │ │ ├── CMakeLists.txt │ │ │ ├── include/ │ │ │ │ └── adder │ │ │ ├── src/ │ │ │ │ └── adder.cpp │ │ │ └── test/ │ │ │ └── adder_test.cpp │ │ ├── build.gradle │ │ ├── gradle/ │ │ │ └── wrapper/ │ │ │ ├── gradle-wrapper.jar │ │ │ └── gradle-wrapper.properties │ │ ├── gradle.properties │ │ ├── gradlew │ │ ├── gradlew.bat │ │ └── settings.gradle │ ├── BasicSample/ │ │ ├── .google/ │ │ │ └── packaging.yaml │ │ ├── README.md │ │ ├── app/ │ │ │ ├── build.gradle │ │ │ └── src/ │ │ │ ├── main/ │ │ │ │ ├── AndroidManifest.xml │ │ │ │ ├── java/ │ │ │ │ │ └── com/ │ │ │ │ │ └── example/ │ │ │ │ │ └── android/ │ │ │ │ │ └── testing/ │ │ │ │ │ └── unittesting/ │ │ │ │ │ └── BasicSample/ │ │ │ │ │ ├── EmailValidator.java │ │ │ │ │ ├── MainActivity.java │ │ │ │ │ ├── SharedPreferenceEntry.java │ │ │ │ │ └── SharedPreferencesHelper.java │ │ │ │ └── res/ │ │ │ │ ├── layout/ │ │ │ │ │ └── activity_main.xml │ │ │ │ ├── values/ │ │ │ │ │ ├── dimens.xml │ │ │ │ │ ├── strings.xml │ │ │ │ │ └── styles.xml │ │ │ │ ├── values-v21/ │ │ │ │ │ ├── dimens.xml │ │ │ │ │ └── styles.xml │ │ │ │ └── values-w820dp/ │ │ │ │ └── dimens.xml │ │ │ └── test/ │ │ │ └── java/ │ │ │ └── com/ │ │ │ └── example/ │ │ │ └── android/ │ │ │ └── testing/ │ │ │ └── unittesting/ │ │ │ └── BasicSample/ │ │ │ ├── EmailValidatorTest.java │ │ │ └── SharedPreferencesHelperTest.java │ │ ├── build.gradle │ │ ├── gradle/ │ │ │ └── wrapper/ │ │ │ ├── gradle-wrapper.jar │ │ │ └── gradle-wrapper.properties │ │ ├── gradle.properties │ │ ├── gradlew │ │ ├── gradlew.bat │ │ └── settings.gradle │ ├── BasicSample-kotlinApp/ │ │ ├── .google/ │ │ │ └── packaging.yaml │ │ ├── README.md │ │ ├── app/ │ │ │ ├── build.gradle │ │ │ └── src/ │ │ │ ├── main/ │ │ │ │ ├── AndroidManifest.xml │ │ │ │ ├── java/ │ │ │ │ │ └── com/ │ │ │ │ │ └── example/ │ │ │ │ │ └── android/ │ │ │ │ │ └── testing/ │ │ │ │ │ └── unittesting/ │ │ │ │ │ └── BasicSample/ │ │ │ │ │ ├── EmailValidator.kt │ │ │ │ │ ├── MainActivity.kt │ │ │ │ │ ├── SharedPreferenceEntry.kt │ │ │ │ │ └── SharedPreferencesHelper.kt │ │ │ │ └── res/ │ │ │ │ ├── layout/ │ │ │ │ │ └── activity_main.xml │ │ │ │ ├── values/ │ │ │ │ │ ├── dimens.xml │ │ │ │ │ ├── strings.xml │ │ │ │ │ └── styles.xml │ │ │ │ ├── values-v21/ │ │ │ │ │ ├── dimens.xml │ │ │ │ │ └── styles.xml │ │ │ │ └── values-w820dp/ │ │ │ │ └── dimens.xml │ │ │ └── test/ │ │ │ └── java/ │ │ │ └── com/ │ │ │ └── example/ │ │ │ └── android/ │ │ │ └── testing/ │ │ │ └── unittesting/ │ │ │ └── BasicSample/ │ │ │ ├── EmailValidatorTest.kt │ │ │ └── SharedPreferencesHelperTest.kt │ │ ├── build.gradle │ │ ├── gradle/ │ │ │ └── wrapper/ │ │ │ ├── gradle-wrapper.jar │ │ │ └── gradle-wrapper.properties │ │ ├── gradle.properties │ │ ├── gradlew │ │ ├── gradlew.bat │ │ └── settings.gradle │ └── BasicUnitAndroidTest/ │ ├── .gitignore │ ├── README.md │ ├── app/ │ │ ├── build.gradle │ │ └── src/ │ │ ├── androidTest/ │ │ │ └── java/ │ │ │ └── com/ │ │ │ └── example/ │ │ │ └── android/ │ │ │ └── testing/ │ │ │ └── unittesting/ │ │ │ └── basicunitandroidtest/ │ │ │ └── LogHistoryAndroidUnitTest.java │ │ └── main/ │ │ ├── AndroidManifest.xml │ │ ├── java/ │ │ │ └── com/ │ │ │ └── example/ │ │ │ └── android/ │ │ │ └── testing/ │ │ │ └── unittesting/ │ │ │ └── basicunitandroidtest/ │ │ │ ├── LogHistory.java │ │ │ └── MainActivity.java │ │ └── res/ │ │ ├── layout/ │ │ │ └── activity_main.xml │ │ ├── values/ │ │ │ ├── dimens.xml │ │ │ ├── strings.xml │ │ │ └── styles.xml │ │ ├── values-v21/ │ │ │ └── styles.xml │ │ └── values-w820dp/ │ │ └── dimens.xml │ ├── build.gradle │ ├── gradle/ │ │ └── wrapper/ │ │ ├── gradle-wrapper.jar │ │ └── gradle-wrapper.properties │ ├── gradle.properties │ ├── gradlew │ ├── gradlew.bat │ └── settings.gradle └── update_versions.sh ================================================ FILE CONTENTS ================================================ ================================================ FILE: .bazelrc ================================================ # Configurations for testing with Bazel # Select a configuration by running `bazel test //my:target --config={headless, gui, local_device}` # Headless instrumentation tests test:headless --test_arg=--enable_display=false # Graphical instrumentation tests. Ensure that $DISPLAY is set. test:gui --test_env=DISPLAY test:gui --test_arg=--enable_display=true # Testing with a local emulator or device. Ensure that `adb devices` lists the device. # Run tests serially. test:local_device --test_strategy=exclusive # Use the local device broker type, as opposed to WRAPPED_EMULATOR. test:local_device --test_arg=--device_broker_type=LOCAL_ADB_SERVER # Uncomment and set $device_id if there is more than one connected device. # test:local_device --test_arg=--device_serial_number=$device_id test --flaky_test_attempts=3 # The unified launcher runs in Python 2 host configuration # https://github.com/bazelbuild/bazel/issues/7899 build --host_force_python=PY2 # ------------------------ # General RBE configuration # ------------------------ build:remote --jobs=100 # Java toolchain setup build:remote --java_toolchain=@bazel_tools//tools/jdk:toolchain_hostjdk8 build:remote --host_java_toolchain=@bazel_tools//tools/jdk:toolchain_hostjdk8 build:remote --host_javabase=@rbe_default//java:jdk build:remote --javabase=@rbe_default//java:jdk # C++ toolchain setup build:remote --extra_toolchains=@rbe_default//config:cc-toolchain build:remote --crosstool_top=@rbe_default//cc:toolchain # Remote instance setup build:remote --remote_instance_name=projects/bazel-untrusted/instances/default_instance build:remote --project_id=bazel-untrusted # Set various strategies so that all actions execute remotely. Mixing remote # and local execution will lead to errors unless the toolchain and remote # machine exactly match the host machine. build:remote --spawn_strategy=remote build:remote --define=EXECUTOR=remote # Enable the remote cache so action results can be shared across machines, # developers, and workspaces. build:remote --remote_cache=remotebuildexecution.googleapis.com # Enable remote execution so actions are performed on the remote systems. build:remote --remote_executor=remotebuildexecution.googleapis.com # Enable authentication. This will pick up application default credentials by # default. build:remote --google_default_credentials # ------------------------------------------- # Custom RBE configuration for Android builds # ------------------------------------------- build:remote_android --config=remote # Reuse general configuration # Platform configuration build:remote_android --extra_execution_platforms=:android_platform build:remote_android --host_platform=:android_platform build:remote_android --platforms=:android_platform build:remote_android --strategy=DexBuilder=remote build:remote_android --noexperimental_check_desugar_deps # Workaround for singlejar incompatibility with RBE build:remote_android --incompatible_strict_action_env ================================================ FILE: .github/ci-gradle.properties ================================================ ================================================ FILE: .github/workflows/composescreenshot.yml ================================================ # Workflow name name: Compose Preview Screenshot on: workflow_dispatch: push: branches: [ main ] # When it will be triggered # And in which branch pull_request: branches: [ main ] jobs: build: runs-on: ubuntu-latest steps: - uses: actions/checkout@v3 - name: Set Up JDK uses: actions/setup-java@v3 with: distribution: 'zulu' # See 'Supported distributions' for available options java-version: '17' cache: 'gradle' - name: Build project and run screenshot tests working-directory: ./ui/PreviewScreenshot run: ./gradlew validateDebugScreenshotTest ================================================ FILE: .github/workflows/copy-branch.yml ================================================ # Duplicates default main branch to the old master branch name: Duplicates main to old master branch # Controls when the action will run. Triggers the workflow on push or pull request # events but only for the main branch on: workflow_dispatch: push: branches: [ main ] # A workflow run is made up of one or more jobs that can run sequentially or in parallel jobs: # This workflow contains a single job called "copy-branch" copy-branch: # The type of runner that the job will run on runs-on: ubuntu-latest # Steps represent a sequence of tasks that will be executed as part of the job steps: # Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it, # but specifies master branch (old default). - uses: actions/checkout@v2 with: fetch-depth: 0 ref: master - run: | git config user.name github-actions git config user.email github-actions@github.com git merge origin/main git push ================================================ FILE: .github/workflows/gradle-wrapper-validation.yml ================================================ name: Validate Gradle Wrapper on: workflow_dispatch: push: branches: [ main ] pull_request: branches: [ main ] jobs: validation: name: Validation runs-on: ubuntu-latest steps: - uses: actions/checkout@v3 - uses: gradle/wrapper-validation-action@v1 ================================================ FILE: .github/workflows/test-all.yml ================================================ # Workflow name name: Build + Test all on: workflow_dispatch: push: branches: [ main ] # When it will be triggered # And in which branch pull_request: branches: [ main ] jobs: build: runs-on: ubuntu-latest steps: - uses: actions/checkout@v3 - name: Enable KVM group perms run: | echo 'KERNEL=="kvm", GROUP="kvm", MODE="0666", OPTIONS+="static_node=kvm"' | sudo tee /etc/udev/rules.d/99-kvm4all.rules sudo udevadm control --reload-rules sudo udevadm trigger --name-match=kvm ls /dev/kvm - name: Set Up JDK uses: actions/setup-java@v3 with: distribution: 'zulu' # See 'Supported distributions' for available options java-version: '17' cache: 'gradle' - name: Setup Gradle uses: gradle/actions/setup-gradle@v4 - name: Setup Android SDK uses: android-actions/setup-android@v3 - name: Build project and run local and device tests run: ./test_all.sh - name: Upload test reports if: always() uses: actions/upload-artifact@v4 with: name: test-reports path: '**/app/build/reports/androidTests' ================================================ FILE: .gitignore ================================================ .idea *.iml local.properties build .gradle # Eclipse project files .project .settings/ .classpath bazel-* .DS_Store ================================================ FILE: BUILD.bazel ================================================ load("@rules_jvm_external//:defs.bzl", "artifact") load("//:common_defs.bzl", "androidxLibVersion", "coreVersion", "espressoVersion", "extJUnitVersion", "extTruthVersion", "rulesVersion", "runnerVersion") licenses(["notice"]) # Apache 2.0 android_library( name = "test_deps", visibility = ["//visibility:public"], exports = [ artifact("androidx.annotation:annotation"), artifact("androidx.test.espresso:espresso-core"), artifact("androidx.test:rules"), artifact("androidx.test:runner"), artifact("androidx.test:monitor"), artifact("androidx.test.ext:junit"), artifact("androidx.test:core"), artifact("com.google.guava:guava"), artifact("com.google.inject:guice"), artifact("javax.inject:javax.inject"), artifact("junit:junit"), artifact("org.hamcrest:java-hamcrest"), ], ) # Platform configuration for emulators on RBE for Bazel CI platform( name = "android_platform", constraint_values = [ "@bazel_tools//platforms:x86_64", "@bazel_tools//platforms:linux", "@bazel_toolchains//constraints:xenial", "@bazel_tools//tools/cpp:clang", ], # TODO(@jin): s/di-cloud-exp/rbe-containers/ when the official android-test container with libxcursor1 and libxcomposite1 is ready. # URI for official container: docker://gcr.io/rbe-containers/ubuntu16_04-android_test@sha256: remote_execution_properties = """ properties: { name: "container-image" value: "docker://gcr.io/di-cloud-exp/rbe-ubuntu16-04-android@sha256:eb3828f71faf595f44b20b97d205e73e8a21982f1d7a170c3ec8f9d33ce3179a" } properties: { name: "dockerNetwork" value: "standard" } properties: { name: "dockerPrivileged" value: "true" } properties: { name: "gceMachineType" value: "n1-standard-2" } """, ) ================================================ FILE: CODEOWNERS ================================================ * @josealcerreca ================================================ FILE: CONTRIBUTING.md ================================================ # How to become a contributor and submit your own code To contribute with a small fix, simply create a pull request. If you want to add a new sample or plan to request a big change, [contact us](https://groups.google.com/forum/#!forum/android-testing-support-library) first. ## Contributing new samples If you want to contribute full samples, we'd love to review and accept them. In case you need ideas, these are some samples on the roadmap: * Advanced Idling Resource * RecyclerView actions * Sharding * RunListener * Rules You can also contribute to this list if you have a sample request. ## Code style and structure Please check out the [Code Style for Contributors](https://source.android.com/source/code-style.html) section in AOSP. Also, check out the rest of the samples and maintain as much consistency with them as possible. ## Contributor License Agreements We'd love to accept your sample apps and patches! Before we can take them, we have to jump a couple of legal hurdles. Please fill out either the individual or corporate Contributor License Agreement (CLA). * If you are an individual writing original source code and you're sure you own the intellectual property, then you'll need to sign an [individual CLA] (https://cla.developers.google.com). * If you work for a company that wants to allow you to contribute your work, then you'll need to sign a [corporate CLA] (https://cla.developers.google.com). * Please make sure you sign both, Android and Google CLA Follow either of the two links above to access the appropriate CLA and instructions for how to sign and return it. Once we receive it, we'll be able to accept your pull requests. ## Contributing A Patch 1. Submit an issue describing your proposed change to the repo in question. 1. The repo owner will respond to your issue promptly. 1. If your proposed change is accepted, and you haven't already done so, sign a Contributor License Agreement (see details above). 1. Fork the desired repo, develop and test your code changes. 1. Ensure that your code adheres to the existing style in the sample to which you are contributing. Refer to the [Android Code Style Guide] (https://source.android.com/source/code-style.html) for the recommended coding standards for this organization. 1. Ensure that your code has an appropriate set of unit tests which all pass. 1. Submit a pull request. ================================================ FILE: LICENSE ================================================ Apache License Version 2.0, January 2004 http://www.apache.org/licenses/ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 1. Definitions. "License" shall mean the terms and conditions for use, reproduction, and distribution as defined by Sections 1 through 9 of this document. "Licensor" shall mean the copyright owner or entity authorized by the copyright owner that is granting the License. "Legal Entity" shall mean the union of the acting entity and all other entities that control, are controlled by, or are under common control with that entity. For the purposes of this definition, "control" means (i) the power, direct or indirect, to cause the direction or management of such entity, whether by contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the outstanding shares, or (iii) beneficial ownership of such entity. "You" (or "Your") shall mean an individual or Legal Entity exercising permissions granted by this License. "Source" form shall mean the preferred form for making modifications, including but not limited to software source code, documentation source, and configuration files. "Object" form shall mean any form resulting from mechanical transformation or translation of a Source form, including but not limited to compiled object code, generated documentation, and conversions to other media types. "Work" shall mean the work of authorship, whether in Source or Object form, made available under the License, as indicated by a copyright notice that is included in or attached to the work (an example is provided in the Appendix below). "Derivative Works" shall mean any work, whether in Source or Object form, that is based on (or derived from) the Work and for which the editorial revisions, annotations, elaborations, or other modifications represent, as a whole, an original work of authorship. For the purposes of this License, Derivative Works shall not include works that remain separable from, or merely link (or bind by name) to the interfaces of, the Work and Derivative Works thereof. "Contribution" shall mean any work of authorship, including the original version of the Work and any modifications or additions to that Work or Derivative Works thereof, that is intentionally submitted to Licensor for inclusion in the Work by the copyright owner or by an individual or Legal Entity authorized to submit on behalf of the copyright owner. For the purposes of this definition, "submitted" means any form of electronic, verbal, or written communication sent to the Licensor or its representatives, including but not limited to communication on electronic mailing lists, source code control systems, and issue tracking systems that are managed by, or on behalf of, the Licensor for the purpose of discussing and improving the Work, but excluding communication that is conspicuously marked or otherwise designated in writing by the copyright owner as "Not a Contribution." "Contributor" shall mean Licensor and any individual or Legal Entity on behalf of whom a Contribution has been received by Licensor and subsequently incorporated within the Work. 2. Grant of Copyright License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable copyright license to reproduce, prepare Derivative Works of, publicly display, publicly perform, sublicense, and distribute the Work and such Derivative Works in Source or Object form. 3. Grant of Patent License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable (except as stated in this section) patent license to make, have made, use, offer to sell, sell, import, and otherwise transfer the Work, where such license applies only to those patent claims licensable by such Contributor that are necessarily infringed by their Contribution(s) alone or by combination of their Contribution(s) with the Work to which such Contribution(s) was submitted. If You institute patent litigation against any entity (including a cross-claim or counterclaim in a lawsuit) alleging that the Work or a Contribution incorporated within the Work constitutes direct or contributory patent infringement, then any patent licenses granted to You under this License for that Work shall terminate as of the date such litigation is filed. 4. Redistribution. You may reproduce and distribute copies of the Work or Derivative Works thereof in any medium, with or without modifications, and in Source or Object form, provided that You meet the following conditions: (a) You must give any other recipients of the Work or Derivative Works a copy of this License; and (b) You must cause any modified files to carry prominent notices stating that You changed the files; and (c) You must retain, in the Source form of any Derivative Works that You distribute, all copyright, patent, trademark, and attribution notices from the Source form of the Work, excluding those notices that do not pertain to any part of the Derivative Works; and (d) If the Work includes a "NOTICE" text file as part of its distribution, then any Derivative Works that You distribute must include a readable copy of the attribution notices contained within such NOTICE file, excluding those notices that do not pertain to any part of the Derivative Works, in at least one of the following places: within a NOTICE text file distributed as part of the Derivative Works; within the Source form or documentation, if provided along with the Derivative Works; or, within a display generated by the Derivative Works, if and wherever such third-party notices normally appear. The contents of the NOTICE file are for informational purposes only and do not modify the License. You may add Your own attribution notices within Derivative Works that You distribute, alongside or as an addendum to the NOTICE text from the Work, provided that such additional attribution notices cannot be construed as modifying the License. You may add Your own copyright statement to Your modifications and may provide additional or different license terms and conditions for use, reproduction, or distribution of Your modifications, or for any such Derivative Works as a whole, provided Your use, reproduction, and distribution of the Work otherwise complies with the conditions stated in this License. 5. Submission of Contributions. Unless You explicitly state otherwise, any Contribution intentionally submitted for inclusion in the Work by You to the Licensor shall be under the terms and conditions of this License, without any additional terms or conditions. Notwithstanding the above, nothing herein shall supersede or modify the terms of any separate license agreement you may have executed with Licensor regarding such Contributions. 6. Trademarks. This License does not grant permission to use the trade names, trademarks, service marks, or product names of the Licensor, except as required for reasonable and customary use in describing the origin of the Work and reproducing the content of the NOTICE file. 7. Disclaimer of Warranty. Unless required by applicable law or agreed to in writing, Licensor provides the Work (and each Contributor provides its Contributions) on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, including, without limitation, any warranties or conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are solely responsible for determining the appropriateness of using or redistributing the Work and assume any risks associated with Your exercise of permissions under this License. 8. Limitation of Liability. In no event and under no legal theory, whether in tort (including negligence), contract, or otherwise, unless required by applicable law (such as deliberate and grossly negligent acts) or agreed to in writing, shall any Contributor be liable to You for damages, including any direct, indirect, special, incidental, or consequential damages of any character arising as a result of this License or out of the use or inability to use the Work (including but not limited to damages for loss of goodwill, work stoppage, computer failure or malfunction, or any and all other commercial damages or losses), even if such Contributor has been advised of the possibility of such damages. 9. Accepting Warranty or Additional Liability. While redistributing the Work or Derivative Works thereof, You may choose to offer, and charge a fee for, acceptance of support, warranty, indemnity, or other liability obligations and/or rights consistent with this License. However, in accepting such obligations, You may act only on Your own behalf and on Your sole responsibility, not on behalf of any other Contributor, and only if You agree to indemnify, defend, and hold each Contributor harmless for any liability incurred by, or claims asserted against, such Contributor by reason of your accepting any such warranty or additional liability. END OF TERMS AND CONDITIONS APPENDIX: How to apply the Apache License to your work. To apply the Apache License to your work, attach the following boilerplate notice, with the fields enclosed by brackets "[]" replaced with your own identifying information. (Don't include the brackets!) The text should be enclosed in the appropriate comment syntax for the file format. We also recommend that a file or class name and description of purpose be included on the same "printed page" as the copyright notice for easier identification within third-party archives. Copyright 2014 The Android Open Source Project Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. ================================================ FILE: README.md ================================================ Android testing samples =================================== A collection of samples demonstrating different frameworks and techniques for automated testing. ### Espresso Samples **[BasicSample](https://github.com/googlesamples/android-testing/blob/main/ui/espresso/BasicSample)** - Basic Espresso sample **[CustomMatcherSample](https://github.com/googlesamples/android-testing/blob/main/ui/espresso/CustomMatcherSample)** - Shows how to extend Espresso to match the *hint* property of an EditText **[DataAdapterSample](https://github.com/googlesamples/android-testing/blob/main/ui/espresso/DataAdapterSample)** - Showcases the `onData()` entry point for Espresso, for lists and AdapterViews **[FragmentScenarioSample](https://github.com/googlesamples/android-testing/blob/main/ui/espresso/FragmentScenarioSample)** - Basic usage of `FragmentScenario` with Espresso. **[IdlingResourceSample](https://github.com/googlesamples/android-testing/blob/main/ui/espresso/IdlingResourceSample)** - Synchronization with background jobs **[IntentsBasicSample](https://github.com/googlesamples/android-testing/blob/main/ui/espresso/IntentsBasicSample)** - Basic usage of `intended()` and `intending()` **[IntentsAdvancedSample](https://github.com/googlesamples/android-testing/blob/main/ui/espresso/IntentsAdvancedSample)** - Simulates a user fetching a bitmap using the camera **[MultiWindowSample](https://github.com/googlesamples/android-testing/blob/main/ui/espresso/MultiWindowSample)** - Shows how to point Espresso to different windows **[RecyclerViewSample](https://github.com/googlesamples/android-testing/blob/main/ui/espresso/RecyclerViewSample)** - RecyclerView actions for Espresso **[ScreenshotSample](https://github.com/googlesamples/android-testing/blob/main/ui/espresso/ScreenshotSample)** - Screenshot capturing and saving using Espresso and androidx.test.core APIs **[WebBasicSample](https://github.com/googlesamples/android-testing/blob/main/ui/espresso/WebBasicSample)** - Use Espresso-web to interact with WebViews **[BasicSampleBundled](https://github.com/googlesamples/android-testing/blob/main/ui/espresso/BasicSampleBundled)** - Basic sample for Eclipse and other IDEs **[MultiProcessSample](https://github.com/googlesamples/android-testing/blob/main/ui/espresso/MultiProcessSample)** - Showcases how to use multiprocess Espresso. ### UiAutomator Sample **[BasicSample](https://github.com/googlesamples/android-testing/tree/main/ui/uiautomator/BasicSample)** - Basic UI Automator sample ### AndroidJUnitRunner Sample **[AndroidJunitRunnerSample](https://github.com/googlesamples/android-testing/tree/main/runner/AndroidJunitRunnerSample)** - Showcases test annotations, parameterized tests and testsuite creation ### JUnit4 Rules Sample **All previous samples use ActivityTestRule or IntentsTestRule but there's one specific to ServiceTestRule: **[BasicSample](https://github.com/googlesamples/android-testing/blob/main/ui/espresso/BasicSample)** - Simple usage of `ActivityTestRule` **[IntentsBasicSample](https://github.com/googlesamples/android-testing/blob/main/ui/espresso/IntentsBasicSample)** - Simple usage of `IntentsTestRule` **[ServiceTestRuleSample](https://github.com/googlesamples/android-testing/tree/main/integration/ServiceTestRuleSample)** - Simple usage of `ServiceTestRule` Prerequisites -------------- - Android SDK v28 - Android Build Tools v28.03 Getting Started --------------- These samples use the Gradle build system. To build a project, enter the project directory and use the `./gradlew assemble` command or use "Import Project" in Android Studio. - Use `./gradlew connectedAndroidTest` to run the tests on a connected emulator or device. - Use `./gradlew test` to run the unit test on your local host. There is a top-level `build.gradle` file if you want to build and test all samples from the root directory. This is mostly helpful to build on a CI (Continuous Integration) server. AndroidX Test Library --------------- Many of these samples use the AndroidX Test Library. Visit the [Testing site on developer.android.com](https://developer.android.com/training/testing) for more information. Experimental Bazel Support -------------------------- [![Build status](https://badge.buildkite.com/18dda320b265e9a8f20cb6141b1e80ca58fb62bdb443e527be.svg)](https://buildkite.com/bazel/android-testing) Some of these samples can be tested with [Bazel](https://bazel.build) on Linux. These samples contain a `BUILD.bazel` file, which is similar to a `build.gradle` file. The external dependencies are defined in the top level `WORKSPACE` file. This is __experimental__ feature. To run the tests, please install the latest version of Bazel (0.12.0 or later) by following the [instructions on the Bazel website](https://docs.bazel.build/versions/master/install-ubuntu.html). ### Bazel commands ``` # Clone the repository if you haven't. $ git clone https://github.com/google/android-testing $ cd android-testing # Edit the path to your local SDK at the top of the WORKSPACE file $ $EDITOR WORKSPACE # Test everything in a headless mode (no graphical display) $ bazel test //... --config=headless # Test a single test, e.g. ui/espresso/BasicSample/BUILD.bazel $ bazel test //ui/uiautomator/BasicSample:BasicSampleInstrumentationTest_21_x86 --config=headless # Query for all android_instrumentation_test targets $ bazel query 'kind(android_instrumentation_test, //...)' //ui/uiautomator/BasicSample:BasicSampleInstrumentationTest_23_x86 //ui/uiautomator/BasicSample:BasicSampleInstrumentationTest_22_x86 //ui/uiautomator/BasicSample:BasicSampleInstrumentationTest_21_x86 //ui/uiautomator/BasicSample:BasicSampleInstrumentationTest_19_x86 //ui/espresso/RecyclerViewSample:RecyclerViewSampleInstrumentationTest_23_x86 //ui/espresso/RecyclerViewSample:RecyclerViewSampleInstrumentationTest_22_x86 //ui/espresso/RecyclerViewSample:RecyclerViewSampleInstrumentationTest_21_x86 //ui/espresso/RecyclerViewSample:RecyclerViewSampleInstrumentationTest_19_x86 //ui/espresso/MultiWindowSample:MultiWindowSampleInstrumentationTest_23_x86 //ui/espresso/MultiWindowSample:MultiWindowSampleInstrumentationTest_22_x86 ... # Test everything with GUI enabled $ bazel test //... --config=gui # Test with a local device or emulator. Ensure that `adb devices` lists the device. $ bazel test //... --config=local_device # If multiple devices are connected, add --device_serial_number=$identifier where $identifier is the name of the device in `adb devices` $ bazel test //... --config=local_device --test_arg=--device_serial_number=$identifier ``` For more information, check out the documentation for [Android Instrumentation Tests in Bazel](https://docs.bazel.build/versions/master/android-instrumentation-test.html). You may also want to check out [Building an Android App with Bazel](https://docs.bazel.build/versions/master/tutorial/android-app.html), and the list of [Android Rules](https://docs.bazel.build/versions/master/be/android.html) in the Bazel Build Encyclopedia. Known issues: * Building of APKs is supported on Linux, Mac and Windows, but testing is only supported on Linux. * `android_instrumentation_test.target_device` attribute still needs to be specified even if `--config=local_device` is used. * If using a local device or emulator, the APKs are not uninstalled automatically after the test. Use this command to remove the packages: * `adb shell pm list packages com.example.android.testing | cut -d ':' -f 2 | tr -d '\r' | xargs -L1 -t adb uninstall` Please file Bazel related issues against the [Bazel](https://github.com/bazelbuild/bazel) repository instead of this repository. Support ------- - Google+ Community: https://plus.google.com/communities/105153134372062985968 - Stack Overflow: http://stackoverflow.com/questions/tagged/android-testing If you've found an error in this sample, please file an issue: https://github.com/googlesamples/android-testing Patches are encouraged, and may be submitted by forking this project and submitting a pull request through GitHub. Please see CONTRIBUTING.md for more details. License ------- Copyright 2015 The Android Open Source Project, Inc. Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. ================================================ FILE: WORKSPACE ================================================ load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") load("@bazel_tools//tools/build_defs/repo:jvm.bzl", "jvm_maven_import_external") # Set the path to your local SDK installation, or use the ANDROID_HOME environment variable. android_sdk_repository(name = "androidsdk") # Required for running emulator tests on RBE on Bazel CI android_ndk_repository(name = "androidndk") # Android Test Support # # This repository contains the supporting tools to run Android instrumentation tests, # like the emulator definitions (android_device) and the device broker/test runner. ATS_TAG = "1edfdab3134a7f01b37afabd3eebfd2c5bb05151" ATS_SHA256 = "dcd1ff76aef1a26329d77863972780c8fe1fc8ff625747342239f0489c2837ec" http_archive( name = "android_test_support", sha256 = ATS_SHA256, strip_prefix = "android-test-%s" % ATS_TAG, urls = ["https://github.com/android/android-test/archive/%s.tar.gz" % ATS_TAG], ) load("@android_test_support//:repo.bzl", "android_test_repositories") android_test_repositories() load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") RULES_JVM_EXTERNAL_TAG = "3.1" RULES_JVM_EXTERNAL_SHA = "e246373de2353f3d34d35814947aa8b7d0dd1a58c2f7a6c41cfeaff3007c2d14" http_archive( name = "rules_jvm_external", sha256 = RULES_JVM_EXTERNAL_SHA, strip_prefix = "rules_jvm_external-%s" % RULES_JVM_EXTERNAL_TAG, url = "https://github.com/bazelbuild/rules_jvm_external/archive/%s.zip" % RULES_JVM_EXTERNAL_TAG, ) load("@rules_jvm_external//:defs.bzl", "maven_install") load("@rules_jvm_external//:specs.bzl", "maven") load( "//:common_defs.bzl", "androidxLibVersion", "coreVersion", "espressoVersion", "extJUnitVersion", "extTruthVersion", "rulesVersion", "runnerVersion", "uiAutomatorVersion", ) maven_install( name = "maven", artifacts = [ "androidx.annotation:annotation:" + androidxLibVersion, "androidx.core:core:" + androidxLibVersion, "androidx.recyclerview:recyclerview:" + androidxLibVersion, "androidx.test:core:" + coreVersion, "androidx.test.espresso:espresso-accessibility:" + espressoVersion, "androidx.test.espresso:espresso-contrib:" + espressoVersion, "androidx.test.espresso:espresso-core:" + espressoVersion, "androidx.test.espresso:espresso-idling-resource:" + espressoVersion, "androidx.test.espresso:espresso-intents:" + espressoVersion, "androidx.test.ext:junit:" + extJUnitVersion, "androidx.test.ext:truth:" + extTruthVersion, "androidx.test:monitor:" + runnerVersion, "androidx.test:rules:" + rulesVersion, "androidx.test:runner:" + runnerVersion, "androidx.test.uiautomator:uiautomator:" + uiAutomatorVersion, "androidx.viewpager:viewpager:1.0.0", maven.artifact( "com.google.inject", "guice", "4.0", neverlink = True, ), "junit:junit:4.12", "javax.inject:javax.inject:1", "org.hamcrest:java-hamcrest:2.0.0.0", maven.artifact( "org.robolectric", "robolectric", "4.3-beta-1", neverlink = True, exclusions = ["com.google.guava:guava"], ), "com.google.guava:guava:26.0-android", "com.google.truth:truth:0.42", "com.google.android.apps.common.testing.accessibility.framework:accessibility-test-framework:2.0", ], jetify = True, repositories = [ "https://maven.google.com", "https://repo1.maven.org/maven2", ], version_conflict_policy = "pinned", ) http_archive( name = "bazel_toolchains", sha256 = "4d348abfaddbcee0c077fc51bb1177065c3663191588ab3d958f027cbfe1818b", strip_prefix = "bazel-toolchains-2.1.0", urls = [ "https://github.com/bazelbuild/bazel-toolchains/releases/download/2.1.0/bazel-toolchains-2.1.0.tar.gz", "https://mirror.bazel.build/github.com/bazelbuild/bazel-toolchains/archive/2.1.0.tar.gz", ], ) load("@bazel_toolchains//rules:rbe_repo.bzl", "rbe_autoconfig") rbe_autoconfig(name = "rbe_default") ================================================ FILE: bazelci/buildkite-pipeline.yml ================================================ # https://github.com/googlesamples/android-testing#experimental-bazel-support --- platforms: ubuntu1804: build_targets: - "//..." - "-//ui/uiautomator/BasicSample:BasicSampleInstrumentationTest_23_x86" # BazelCI does not have Android Emulator - "-//ui/uiautomator/BasicSample:BasicSampleInstrumentationTest_22_x86" - "-//ui/uiautomator/BasicSample:BasicSampleInstrumentationTest_21_x86" - "-//ui/uiautomator/BasicSample:BasicSampleInstrumentationTest_19_x86" - "-//ui/espresso/RecyclerViewSample:RecyclerViewSampleInstrumentationTest_23_x86" - "-//ui/espresso/RecyclerViewSample:RecyclerViewSampleInstrumentationTest_22_x86" - "-//ui/espresso/RecyclerViewSample:RecyclerViewSampleInstrumentationTest_21_x86" - "-//ui/espresso/RecyclerViewSample:RecyclerViewSampleInstrumentationTest_19_x86" - "-//ui/espresso/MultiWindowSample:MultiWindowSampleInstrumentationTest_23_x86" - "-//ui/espresso/MultiWindowSample:MultiWindowSampleInstrumentationTest_22_x86" - "-//ui/espresso/MultiWindowSample:MultiWindowSampleInstrumentationTest_21_x86" - "-//ui/espresso/MultiWindowSample:MultiWindowSampleInstrumentationTest_19_x86" - "-//ui/espresso/IntentsBasicSample:IntentsBasicSampleInstrumentationTest_23_x86" - "-//ui/espresso/IntentsBasicSample:IntentsBasicSampleInstrumentationTest_22_x86" - "-//ui/espresso/IntentsBasicSample:IntentsBasicSampleInstrumentationTest_21_x86" - "-//ui/espresso/IntentsBasicSample:IntentsBasicSampleInstrumentationTest_19_x86" - "-//ui/espresso/IntentsAdvancedSample:IntentsAdvancedSampleInstrumentationTest_23_x86" - "-//ui/espresso/IntentsAdvancedSample:IntentsAdvancedSampleInstrumentationTest_22_x86" - "-//ui/espresso/IntentsAdvancedSample:IntentsAdvancedSampleInstrumentationTest_21_x86" - "-//ui/espresso/IntentsAdvancedSample:IntentsAdvancedSampleInstrumentationTest_19_x86" - "-//ui/espresso/IdlingResourceSample:IdlingResourceSampleInstrumentationTest_23_x86" - "-//ui/espresso/IdlingResourceSample:IdlingResourceSampleInstrumentationTest_22_x86" - "-//ui/espresso/IdlingResourceSample:IdlingResourceSampleInstrumentationTest_21_x86" - "-//ui/espresso/IdlingResourceSample:IdlingResourceSampleInstrumentationTest_19_x86" - "-//ui/espresso/DataAdapterSample:DataAdapterSampleInstrumentationTest_23_x86" - "-//ui/espresso/DataAdapterSample:DataAdapterSampleInstrumentationTest_22_x86" - "-//ui/espresso/DataAdapterSample:DataAdapterSampleInstrumentationTest_21_x86" - "-//ui/espresso/DataAdapterSample:DataAdapterSampleInstrumentationTest_19_x86" - "-//ui/espresso/CustomMatcherSample:CustomMatcherSampleInstrumentationTest_23_x86" - "-//ui/espresso/CustomMatcherSample:CustomMatcherSampleInstrumentationTest_22_x86" - "-//ui/espresso/CustomMatcherSample:CustomMatcherSampleInstrumentationTest_21_x86" - "-//ui/espresso/CustomMatcherSample:CustomMatcherSampleInstrumentationTest_19_x86" - "-//ui/espresso/BasicSample:BasicSampleInstrumentationTest_23_x86" - "-//ui/espresso/BasicSample:BasicSampleInstrumentationTest_22_x86" - "-//ui/espresso/BasicSample:BasicSampleInstrumentationTest_21_x86" - "-//ui/espresso/BasicSample:BasicSampleInstrumentationTest_19_x86" - "-//ui/espresso/AccessibilitySample:BasicSampleInstrumentationTest_23_x86" - "-//ui/espresso/AccessibilitySample:BasicSampleInstrumentationTest_22_x86" - "-//ui/espresso/AccessibilitySample:BasicSampleInstrumentationTest_21_x86" - "-//ui/espresso/AccessibilitySample:BasicSampleInstrumentationTest_19_x86" test_flags: - "--config=remote_android" - "--flaky_test_attempts=3" test_targets: - "//..." - "-//ui/espresso/AccessibilitySample/..." - "-//ui/uiautomator/BasicSample:BasicSampleInstrumentationTest_23_x86" # BazelCI does not have Android Emulator - "-//ui/uiautomator/BasicSample:BasicSampleInstrumentationTest_22_x86" - "-//ui/uiautomator/BasicSample:BasicSampleInstrumentationTest_21_x86" - "-//ui/uiautomator/BasicSample:BasicSampleInstrumentationTest_19_x86" - "-//ui/espresso/RecyclerViewSample:RecyclerViewSampleInstrumentationTest_23_x86" - "-//ui/espresso/RecyclerViewSample:RecyclerViewSampleInstrumentationTest_22_x86" - "-//ui/espresso/RecyclerViewSample:RecyclerViewSampleInstrumentationTest_21_x86" - "-//ui/espresso/RecyclerViewSample:RecyclerViewSampleInstrumentationTest_19_x86" - "-//ui/espresso/MultiWindowSample:MultiWindowSampleInstrumentationTest_23_x86" - "-//ui/espresso/MultiWindowSample:MultiWindowSampleInstrumentationTest_22_x86" - "-//ui/espresso/MultiWindowSample:MultiWindowSampleInstrumentationTest_21_x86" - "-//ui/espresso/MultiWindowSample:MultiWindowSampleInstrumentationTest_19_x86" - "-//ui/espresso/IntentsBasicSample:IntentsBasicSampleInstrumentationTest_23_x86" - "-//ui/espresso/IntentsBasicSample:IntentsBasicSampleInstrumentationTest_22_x86" - "-//ui/espresso/IntentsBasicSample:IntentsBasicSampleInstrumentationTest_21_x86" - "-//ui/espresso/IntentsBasicSample:IntentsBasicSampleInstrumentationTest_19_x86" - "-//ui/espresso/IntentsAdvancedSample:IntentsAdvancedSampleInstrumentationTest_23_x86" - "-//ui/espresso/IntentsAdvancedSample:IntentsAdvancedSampleInstrumentationTest_22_x86" - "-//ui/espresso/IntentsAdvancedSample:IntentsAdvancedSampleInstrumentationTest_21_x86" - "-//ui/espresso/IntentsAdvancedSample:IntentsAdvancedSampleInstrumentationTest_19_x86" - "-//ui/espresso/IdlingResourceSample:IdlingResourceSampleInstrumentationTest_23_x86" - "-//ui/espresso/IdlingResourceSample:IdlingResourceSampleInstrumentationTest_22_x86" - "-//ui/espresso/IdlingResourceSample:IdlingResourceSampleInstrumentationTest_21_x86" - "-//ui/espresso/IdlingResourceSample:IdlingResourceSampleInstrumentationTest_19_x86" - "-//ui/espresso/DataAdapterSample:DataAdapterSampleInstrumentationTest_23_x86" - "-//ui/espresso/DataAdapterSample:DataAdapterSampleInstrumentationTest_22_x86" - "-//ui/espresso/DataAdapterSample:DataAdapterSampleInstrumentationTest_21_x86" - "-//ui/espresso/DataAdapterSample:DataAdapterSampleInstrumentationTest_19_x86" - "-//ui/espresso/CustomMatcherSample:CustomMatcherSampleInstrumentationTest_23_x86" - "-//ui/espresso/CustomMatcherSample:CustomMatcherSampleInstrumentationTest_22_x86" - "-//ui/espresso/CustomMatcherSample:CustomMatcherSampleInstrumentationTest_21_x86" - "-//ui/espresso/CustomMatcherSample:CustomMatcherSampleInstrumentationTest_19_x86" - "-//ui/espresso/BasicSample:BasicSampleInstrumentationTest_23_x86" - "-//ui/espresso/BasicSample:BasicSampleInstrumentationTest_22_x86" - "-//ui/espresso/BasicSample:BasicSampleInstrumentationTest_21_x86" - "-//ui/espresso/BasicSample:BasicSampleInstrumentationTest_19_x86" - "-//ui/espresso/AccessibilitySample:BasicSampleInstrumentationTest_23_x86" - "-//ui/espresso/AccessibilitySample:BasicSampleInstrumentationTest_22_x86" - "-//ui/espresso/AccessibilitySample:BasicSampleInstrumentationTest_21_x86" - "-//ui/espresso/AccessibilitySample:BasicSampleInstrumentationTest_19_x86" macos: # Testing does not work for macos and windows yet build_targets: # Results of `bazel query 'kind(android_binary, //...)' - "//ui/uiautomator/BasicSample:BasicSampleTest" - "//ui/uiautomator/BasicSample:BasicSample" - "//ui/espresso/RecyclerViewSample:RecyclerViewSampleTest" - "//ui/espresso/RecyclerViewSample:RecyclerViewSample" - "//ui/espresso/MultiWindowSample:MultiWindowSampleTest" - "//ui/espresso/MultiWindowSample:MultiWindowSample" - "//ui/espresso/IntentsBasicSample:IntentsBasicSampleTest" - "//ui/espresso/IntentsBasicSample:IntentsBasicSample" - "//ui/espresso/IntentsAdvancedSample:IntentsAdvancedSampleTest" - "//ui/espresso/IntentsAdvancedSample:IntentsAdvancedSample" - "//ui/espresso/IdlingResourceSample:IdlingResourceSampleTest" - "//ui/espresso/IdlingResourceSample:IdlingResourceSample" - "//ui/espresso/DataAdapterSample:DataAdapterSampleTest" - "//ui/espresso/DataAdapterSample:DataAdapterSample" - "//ui/espresso/CustomMatcherSample:CustomMatcherSampleTest" - "//ui/espresso/CustomMatcherSample:CustomMatcherSample" - "//ui/espresso/BasicSample:BasicSampleTest" - "//ui/espresso/BasicSample:BasicSample" - "//ui/espresso/AccessibilitySample:BasicSampleTest" - "//ui/espresso/AccessibilitySample:BasicSample" windows: build_targets: # Results of `bazel query 'kind(android_binary, //...)' - "//ui/uiautomator/BasicSample:BasicSampleTest" - "//ui/uiautomator/BasicSample:BasicSample" - "//ui/espresso/RecyclerViewSample:RecyclerViewSampleTest" - "//ui/espresso/RecyclerViewSample:RecyclerViewSample" - "//ui/espresso/MultiWindowSample:MultiWindowSampleTest" - "//ui/espresso/MultiWindowSample:MultiWindowSample" - "//ui/espresso/IntentsBasicSample:IntentsBasicSampleTest" - "//ui/espresso/IntentsBasicSample:IntentsBasicSample" - "//ui/espresso/IntentsAdvancedSample:IntentsAdvancedSampleTest" - "//ui/espresso/IntentsAdvancedSample:IntentsAdvancedSample" - "//ui/espresso/IdlingResourceSample:IdlingResourceSampleTest" - "//ui/espresso/IdlingResourceSample:IdlingResourceSample" - "//ui/espresso/DataAdapterSample:DataAdapterSampleTest" - "//ui/espresso/DataAdapterSample:DataAdapterSample" - "//ui/espresso/CustomMatcherSample:CustomMatcherSampleTest" - "//ui/espresso/CustomMatcherSample:CustomMatcherSample" - "//ui/espresso/BasicSample:BasicSampleTest" - "//ui/espresso/BasicSample:BasicSample" - "//ui/espresso/AccessibilitySample:BasicSampleTest" - "//ui/espresso/AccessibilitySample:BasicSample" ================================================ FILE: common_defs.bzl ================================================ # Common constants for bazel builds # keep naming convention consistent with gradle variables, so version numbers can be auto-incremented # via a script androidxLibVersion = "1.0.0" coreVersion = "1.2.0-beta01" extJUnitVersion = "1.1.1-beta01" extTruthVersion = "1.2.0-beta01" runnerVersion = "1.2.0-beta01" rulesVersion = "1.2.0-beta01" espressoVersion = "3.2.0-beta01" uiAutomatorVersion = "2.2.0" minSdkVersion = "14" targetSdkVersion = "28" ================================================ FILE: integration/ServiceTestRuleSample/.gitignore ================================================ .gradle local.properties .idea .DS_Store build *.iml ================================================ FILE: integration/ServiceTestRuleSample/README.md ================================================ # Basic sample for ServiceTestRule This rule provides a simplified mechanism to start and shutdown your service before and after the duration of your test. It also guarantees that the service is successfully connected when starting (or binding to) a service. The service can be started (or bound) using one of the helper methods. It will automatically be stopped (or unbound) after the test completes and any methods annotated with @After are finished. Note: This rule doesn't support `IntentService` because it's automatically destroyed when `IntentService#onHandleIntent(android.content.Intent)` finishes all outstanding commands. So there is no guarantee to establish a successful connection in a timely manner. This project uses the Gradle build system. You don't need an IDE to build and execute it but Android Studio is recommended. 1. Download the project code, preferably using `git clone`. 1. Open the Android SDK Manager (*Tools* Menu | *Android*) and make sure you have installed the *Support Repository* under *Extras*. 1. In Android Studio, select *File* | *Open...* and point to the `./build.gradle` file. 1. Check out the relevant code: * The application under test is located in `src/main/java` * Tests are in `src/androidTest/java` 1. Connect a device or start an emulator 1. Run the newly created configuration The application will be started on the device/emulator and a series of actions will be performed automatically. If you are using Android Studio, the *Run* window will show the test results. ================================================ FILE: integration/ServiceTestRuleSample/app/build.gradle ================================================ apply plugin: "com.android.application" android { compileSdk 34 defaultConfig { applicationId "com.example.android.testing.integrationtesting.ServiceTestRuleSample" minSdkVersion 21 targetSdkVersion 34 versionCode 1 versionName "1.0" testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" } productFlavors { } testOptions { managedDevices { devices { // run with ../gradlew nexusOneApi30DebugAndroidTest nexusOneApi30(com.android.build.api.dsl.ManagedVirtualDevice) { // A lower resolution device is used here for better emulator performance device = "Nexus One" apiLevel = 30 // Also use the AOSP ATD image for better emulator performance systemImageSource = "aosp-atd" } } } } namespace "com.example.android.testing.ServiceTestRuleSample" lint { abortOnError false } } dependencies { // Testing-only dependencies androidTestImplementation "androidx.test:core:" + rootProject.coreVersion; androidTestImplementation "androidx.test.ext:junit:" + rootProject.extJUnitVersion; androidTestImplementation "androidx.test:runner:" + rootProject.runnerVersion; androidTestImplementation "androidx.test:rules:" + rootProject.rulesVersion; } ================================================ FILE: integration/ServiceTestRuleSample/app/src/androidTest/java/com/example/android/testing/ServiceTestRuleSample/LocalServiceTest.java ================================================ /* * Copyright 2015, The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.example.android.testing.ServiceTestRuleSample; import android.content.Intent; import android.os.IBinder; import androidx.test.ext.junit.runners.AndroidJUnit4; import androidx.test.filters.MediumTest; import androidx.test.rule.ServiceTestRule; import org.junit.Rule; import org.junit.Test; import org.junit.runner.RunWith; import java.util.concurrent.TimeoutException; import static androidx.test.core.app.ApplicationProvider.getApplicationContext; import static org.hamcrest.CoreMatchers.any; import static org.hamcrest.CoreMatchers.is; import static org.junit.Assert.assertThat; /** * JUnit4 test that uses a {@link ServiceTestRule} to interact with a bound service. *

* {@link ServiceTestRule} is a JUnit rule that provides a * simplified mechanism to start and shutdown your service before * and after the duration of your test. It also guarantees that the service is successfully * connected when starting (or binding to) a service. The service can be started * (or bound) using one of the helper methods. It will automatically be stopped (or unbound) after * the test completes and any methods annotated with * After are * finished. *

* Note: This rule doesn't support {@link android.app.IntentService} because it's automatically * destroyed when {@link android.app.IntentService#onHandleIntent(android.content.Intent)} finishes * all outstanding commands. So there is no guarantee to establish a successful connection * in a timely manner. */ @MediumTest @RunWith(AndroidJUnit4.class) public class LocalServiceTest { @Rule public final ServiceTestRule mServiceRule = new ServiceTestRule(); @Test public void testWithBoundService() throws TimeoutException { // Create the service Intent. Intent serviceIntent = new Intent(getApplicationContext(), LocalService.class); // Data can be passed to the service via the Intent. serviceIntent.putExtra(LocalService.SEED_KEY, 42L); // Bind the service and grab a reference to the binder. IBinder binder = mServiceRule.bindService(serviceIntent); // Get the reference to the service, or you can call public methods on the binder directly. LocalService service = ((LocalService.LocalBinder) binder).getService(); // Verify that the service is working correctly. assertThat(service.getRandomInt(), is(any(Integer.class))); } } ================================================ FILE: integration/ServiceTestRuleSample/app/src/main/AndroidManifest.xml ================================================ ================================================ FILE: integration/ServiceTestRuleSample/app/src/main/java/com/example/android/testing/ServiceTestRuleSample/LocalService.java ================================================ /* * Copyright 2015, The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.example.android.testing.ServiceTestRuleSample; import android.app.Service; import android.content.Intent; import android.os.Binder; import android.os.IBinder; import java.util.Random; /** * {@link Service} that generates random numbers. *

* A seed for the random number generator can be set via the {@link Intent} passed to * {@link #onBind(Intent)}. */ public class LocalService extends Service { // Used as a key for the Intent. public static final String SEED_KEY = "SEED_KEY"; // Binder given to clients private final IBinder mBinder = new LocalBinder(); // Random number generator private Random mGenerator = new Random(); private long mSeed; @Override public IBinder onBind(Intent intent) { // If the Intent comes with a seed for the number generator, apply it. if (intent.hasExtra(SEED_KEY)) { mSeed = intent.getLongExtra(SEED_KEY, 0); mGenerator.setSeed(mSeed); } return mBinder; } public class LocalBinder extends Binder { public LocalService getService() { // Return this instance of LocalService so clients can call public methods. return LocalService.this; } } /** * Returns a random integer in [0, 100). */ public int getRandomInt() { return mGenerator.nextInt(100); } } ================================================ FILE: integration/ServiceTestRuleSample/app/src/main/res/values/strings.xml ================================================ ServiceTestRule Basic Sample ================================================ FILE: integration/ServiceTestRuleSample/app/src/main/res/values/styles.xml ================================================ ================================================ FILE: ui/espresso/CustomMatcherSample/app/src/main/res/values-v21/styles.xml ================================================ ================================================ FILE: ui/espresso/FragmentScenarioSample/app/src/sharedTest/java/com/example/android/testing/espresso/fragmentscenario/SampleDialogFragmentTest.kt ================================================ package com.example.android.testing.espresso.fragmentscenario import androidx.fragment.app.testing.launchFragment import androidx.fragment.app.testing.launchFragmentInContainer import androidx.test.espresso.Espresso import androidx.test.espresso.assertion.ViewAssertions import androidx.test.espresso.matcher.RootMatchers.isDialog import androidx.test.espresso.matcher.ViewMatchers import androidx.test.ext.junit.runners.AndroidJUnit4 import com.google.common.truth.Truth.assertThat import org.junit.Test import org.junit.runner.RunWith import org.robolectric.annotation.LooperMode /** * A test using the androidx.test unified API, which can execute on an Android device or locally using Robolectric. * * See [testing documentation](http://d.android.com/tools/testing). */ @RunWith(AndroidJUnit4::class) class SampleDialogFragmentTest { @Test fun launchDialogFragmentAndVerifyUI() { // Use launchFragment to launch the dialog fragment in a dialog. val scenario = launchFragment() scenario.onFragment { fragment -> assertThat(fragment.dialog).isNotNull() assertThat(fragment.requireDialog().isShowing).isTrue() } // Now use espresso to look for the fragment's text view and verify it is displayed. Espresso.onView(ViewMatchers.withId(R.id.textView)).inRoot(isDialog()) .check(ViewAssertions.matches(ViewMatchers.withText("I am a fragment"))); } @Test fun launchDialogFragmentEmbeddedToHostActivityAndVerifyUI() { // Use launchFragmentInContainer to inflate a dialog fragment's view into Activity's content view. val scenario = launchFragmentInContainer() scenario.onFragment { fragment -> // Dialog is not created because you use launchFragmentInContainer and the view is inflated // into the Activity's content view. assertThat(fragment.dialog).isNull() } // Now use espresso to look for the fragment's text view and verify it is displayed. Espresso.onView(ViewMatchers.withId(R.id.textView)) .check(ViewAssertions.matches(ViewMatchers.withText("I am a fragment"))); } } ================================================ FILE: ui/espresso/FragmentScenarioSample/app/src/sharedTest/java/com/example/android/testing/espresso/fragmentscenario/SampleFragmentTest.kt ================================================ package com.example.android.testing.espresso.fragmentscenario import androidx.fragment.app.testing.launchFragmentInContainer import androidx.test.espresso.Espresso.onView import androidx.test.espresso.assertion.ViewAssertions.matches import androidx.test.espresso.matcher.ViewMatchers.withId import androidx.test.espresso.matcher.ViewMatchers.withText import androidx.test.ext.junit.runners.AndroidJUnit4 import org.junit.Test import org.junit.runner.RunWith import org.robolectric.annotation.LooperMode /** * A test using the androidx.test unified API, which can execute on an Android device or locally using Robolectric. * * See [testing documentation](http://d.android.com/tools/testing). */ @RunWith(AndroidJUnit4::class) class SampleFragmentTest { @Test fun launchFragmentAndVerifyUI() { // use launchInContainer to launch the fragment with UI launchFragmentInContainer() // now use espresso to look for the fragment's text view and verify it is displayed onView(withId(R.id.textView)).check(matches(withText("I am a fragment"))); } } ================================================ FILE: ui/espresso/FragmentScenarioSample/build.gradle ================================================ // Top-level build file where you can add configuration options common to all sub-projects/modules. buildscript { ext.kotlinVersion = "1.9.22" ext.agpVersion = "8.5.0" repositories { google() mavenCentral() } dependencies { classpath "com.android.tools.build:gradle:$agpVersion" classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlinVersion" } } allprojects { repositories { google() mavenCentral() } } task clean(type: Delete) { delete rootProject.buildDir } ext { buildToolsVersion = "32.0.0" androidxCoreVersion = "1.9.0" androidxCompatVersion = "1.5.1" androidxFragmentVersion = "1.5.3" coreVersion = "1.6.1" extJUnitVersion = "1.2.1" runnerVersion = "1.6.1" rulesVersion = "1.6.1" espressoVersion = "3.6.1" robolectricVersion = "4.13" truthVersion = "1.1.3" } ================================================ FILE: ui/espresso/FragmentScenarioSample/gradle/wrapper/gradle-wrapper.properties ================================================ #Sat Apr 27 14:01:24 PDT 2019 distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists distributionUrl=https\://services.gradle.org/distributions/gradle-8.7-bin.zip ================================================ FILE: ui/espresso/FragmentScenarioSample/gradle.properties ================================================ # Project-wide Gradle settings. # IDE (e.g. Android Studio) users: # Gradle settings configured through the IDE *will override* # any settings specified in this file. # For more details on how to configure your build environment visit # http://www.gradle.org/docs/current/userguide/build_environment.html # Specifies the JVM arguments used for the daemon process. # The setting is particularly useful for tweaking memory settings. org.gradle.jvmargs=-Xmx1536m # When configured, Gradle will run in incubating parallel mode. # This option should only be used with decoupled projects. More details, visit # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects # org.gradle.parallel=true # AndroidX package structure to make it clearer which packages are bundled with the # Android operating system, and which are packaged with your app's APK # https://developer.android.com/topic/libraries/support-library/androidx-rn android.useAndroidX=true # Automatically convert third-party libraries to use AndroidX android.enableJetifier=true # Kotlin code style for this project: "official" or "obsolete": kotlin.code.style=official android.defaults.buildfeatures.buildconfig=true android.nonTransitiveRClass=false android.nonFinalResIds=false # use compiled resources for Robolectric. See http://robolectric.org/migrating/#migrating-to-40 # Not needed for Android Studio 3.4+ ================================================ FILE: ui/espresso/FragmentScenarioSample/gradlew ================================================ #!/usr/bin/env sh ############################################################################## ## ## Gradle start up script for UN*X ## ############################################################################## # Attempt to set APP_HOME # Resolve links: $0 may be a link PRG="$0" # Need this for relative symlinks. while [ -h "$PRG" ] ; do ls=`ls -ld "$PRG"` link=`expr "$ls" : '.*-> \(.*\)$'` if expr "$link" : '/.*' > /dev/null; then PRG="$link" else PRG=`dirname "$PRG"`"/$link" fi done SAVED="`pwd`" cd "`dirname \"$PRG\"`/" >/dev/null APP_HOME="`pwd -P`" cd "$SAVED" >/dev/null APP_NAME="Gradle" APP_BASE_NAME=`basename "$0"` # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. DEFAULT_JVM_OPTS="" # Use the maximum available, or set MAX_FD != -1 to use that value. MAX_FD="maximum" warn () { echo "$*" } die () { echo echo "$*" echo exit 1 } # OS specific support (must be 'true' or 'false'). cygwin=false msys=false darwin=false nonstop=false case "`uname`" in CYGWIN* ) cygwin=true ;; Darwin* ) darwin=true ;; MINGW* ) msys=true ;; NONSTOP* ) nonstop=true ;; esac CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar # Determine the Java command to use to start the JVM. if [ -n "$JAVA_HOME" ] ; then if [ -x "$JAVA_HOME/jre/sh/java" ] ; then # IBM's JDK on AIX uses strange locations for the executables JAVACMD="$JAVA_HOME/jre/sh/java" else JAVACMD="$JAVA_HOME/bin/java" fi if [ ! -x "$JAVACMD" ] ; then die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME Please set the JAVA_HOME variable in your environment to match the location of your Java installation." fi else JAVACMD="java" which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. Please set the JAVA_HOME variable in your environment to match the location of your Java installation." fi # Increase the maximum file descriptors if we can. if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then MAX_FD_LIMIT=`ulimit -H -n` if [ $? -eq 0 ] ; then if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then MAX_FD="$MAX_FD_LIMIT" fi ulimit -n $MAX_FD if [ $? -ne 0 ] ; then warn "Could not set maximum file descriptor limit: $MAX_FD" fi else warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" fi fi # For Darwin, add options to specify how the application appears in the dock if $darwin; then GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" fi # For Cygwin, switch paths to Windows format before running java if $cygwin ; then APP_HOME=`cygpath --path --mixed "$APP_HOME"` CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` JAVACMD=`cygpath --unix "$JAVACMD"` # We build the pattern for arguments to be converted via cygpath ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` SEP="" for dir in $ROOTDIRSRAW ; do ROOTDIRS="$ROOTDIRS$SEP$dir" SEP="|" done OURCYGPATTERN="(^($ROOTDIRS))" # Add a user-defined pattern to the cygpath arguments if [ "$GRADLE_CYGPATTERN" != "" ] ; then OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" fi # Now convert the arguments - kludge to limit ourselves to /bin/sh i=0 for arg in "$@" ; do CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` else eval `echo args$i`="\"$arg\"" fi i=$((i+1)) done case $i in (0) set -- ;; (1) set -- "$args0" ;; (2) set -- "$args0" "$args1" ;; (3) set -- "$args0" "$args1" "$args2" ;; (4) set -- "$args0" "$args1" "$args2" "$args3" ;; (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; esac fi # Escape application args save () { for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done echo " " } APP_ARGS=$(save "$@") # Collect all arguments for the java command, following the shell quoting and substitution rules eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS" # by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then cd "$(dirname "$0")" fi exec "$JAVACMD" "$@" ================================================ FILE: ui/espresso/FragmentScenarioSample/gradlew.bat ================================================ @if "%DEBUG%" == "" @echo off @rem ########################################################################## @rem @rem Gradle startup script for Windows @rem @rem ########################################################################## @rem Set local scope for the variables with windows NT shell if "%OS%"=="Windows_NT" setlocal set DIRNAME=%~dp0 if "%DIRNAME%" == "" set DIRNAME=. set APP_BASE_NAME=%~n0 set APP_HOME=%DIRNAME% @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. set DEFAULT_JVM_OPTS= @rem Find java.exe if defined JAVA_HOME goto findJavaFromJavaHome set JAVA_EXE=java.exe %JAVA_EXE% -version >NUL 2>&1 if "%ERRORLEVEL%" == "0" goto init echo. echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. echo. echo Please set the JAVA_HOME variable in your environment to match the echo location of your Java installation. goto fail :findJavaFromJavaHome set JAVA_HOME=%JAVA_HOME:"=% set JAVA_EXE=%JAVA_HOME%/bin/java.exe if exist "%JAVA_EXE%" goto init echo. echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% echo. echo Please set the JAVA_HOME variable in your environment to match the echo location of your Java installation. goto fail :init @rem Get command-line arguments, handling Windows variants if not "%OS%" == "Windows_NT" goto win9xME_args :win9xME_args @rem Slurp the command line arguments. set CMD_LINE_ARGS= set _SKIP=2 :win9xME_args_slurp if "x%~1" == "x" goto execute set CMD_LINE_ARGS=%* :execute @rem Setup the command line set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar @rem Execute Gradle "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% :end @rem End local scope for the variables with windows NT shell if "%ERRORLEVEL%"=="0" goto mainEnd :fail rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of rem the _cmd.exe /c_ return code! if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 exit /b 1 :mainEnd if "%OS%"=="Windows_NT" endlocal :omega ================================================ FILE: ui/espresso/FragmentScenarioSample/settings.gradle ================================================ include ':app' ================================================ FILE: ui/espresso/IdlingResourceSample/.gitignore ================================================ .gradle local.properties .idea .DS_Store build *.iml ================================================ FILE: ui/espresso/IdlingResourceSample/BUILD.bazel ================================================ load("@rules_jvm_external//:defs.bzl", "artifact") load("//:common_defs.bzl", "minSdkVersion", "targetSdkVersion") licenses(["notice"]) # Apache 2.0 android_library( name = "IdlingResourceSampleLib", srcs = glob(["app/src/main/**/*.java"]), custom_package = "com.example.android.testing.espresso.IdlingResourceSample", manifest = "app/src/main/AndroidManifest.xml", resource_files = glob(["app/src/main/res/**/*"]), deps = [ artifact("androidx.annotation:annotation"), artifact("androidx.test.espresso:espresso-idling-resource"), artifact("com.google.guava:guava"), ], ) android_binary( name = "IdlingResourceSample", custom_package = "com.example.android.testing.espresso.IdlingResourceSample", manifest = "app/src/main/AppManifest.xml", manifest_values = { "minSdkVersion": minSdkVersion, "targetSdkVersion": targetSdkVersion, }, deps = [":IdlingResourceSampleLib"], ) android_library( name = "IdlingResourceSampleTestLib", srcs = glob(["app/src/androidTest/**/*.java"]), custom_package = "com.example.android.testing.espresso.IdlingResourceSample.test", deps = [ artifact("androidx.test.espresso:espresso_idling_resource"), ":IdlingResourceSampleLib", "//:test_deps", ], ) android_binary( name = "IdlingResourceSampleTest", custom_package = "com.example.android.testing.espresso.IdlingResourceSample.test", instruments = ":IdlingResourceSample", manifest = "app/src/androidTest/AndroidManifest.xml", manifest_values = { "minSdkVersion": minSdkVersion, "targetSdkVersion": targetSdkVersion, }, deps = [":IdlingResourceSampleTestLib"], ) API_LEVELS = [ "19_x86", "21_x86", "22_x86", "23_x86", ] [android_instrumentation_test( name = "IdlingResourceSampleInstrumentationTest_%s" % API_LEVEL, target_device = "@android_test_support//tools/android/emulated_devices/generic_phone:android_%s_qemu2" % API_LEVEL, test_app = ":IdlingResourceSampleTest", ) for API_LEVEL in API_LEVELS] ================================================ FILE: ui/espresso/IdlingResourceSample/README.md ================================================ # Basic Idling Resource sample for Espresso The centerpiece of Espresso is its ability to seamlessly synchronize all test operations with the application under test. By default, Espresso waits for UI events in the current message queue to be processed and default AsyncTasks* to complete before it moves on to the next test operation. This should address the majority of application/test synchronization in your application. However, there are instances where applications perform background operations (such as communicating with web services) via non-standard means; for example: direct creation and management of threads. This sample showcases how to implement a very simple IdlingResource interface and expose it to a test. The application shows a message to the user after a delay that is executed on a different thread. Consider using the CountingIdlingResource class from the espresso-contrib package. It's a very easy to use Idling Resource implementation that can handle multiple parallel operations keeping track of the number of pending operations. Note that the `espresso-idling-resource` dependency is added into the `implementation` scope. This sample use AndroidX: ``` androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.1' implementation 'androidx.test.espresso:espresso-idling-resource:3.1.1' ``` If you haven't yet migrated to AndroidX: ``` androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2' implementation 'com.android.support.test.espresso:espresso-idling-resource:3.0.2' ``` This dependency and its implementation are added to the app under test but are not needed in production. This bloats the released app but it's kept this way to simplify the sample. You can: * ProGuard/shrink your release build to minimize impact * Use a build type or product flavor for tests and remove the Idling Resource classes in the production/release variant. * Add the dependency to `androidTestCompile` and inject an IdlingResource-aware MessageDelayer from the test. * Keep them, since the added methods and size are insignificant. ================================================ FILE: ui/espresso/IdlingResourceSample/app/build.gradle ================================================ /* * Copyright 2016, The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ apply plugin: "com.android.application" android { compileSdk 34 defaultConfig { applicationId "com.example.android.testing.espresso.IdlingResourceSample" minSdkVersion 21 targetSdkVersion 34 versionCode 1 versionName "1.0" testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" } testOptions { unitTests { includeAndroidResources = true } managedDevices { devices { // run with ../gradlew nexusOneApi30DebugAndroidTest nexusOneApi30(com.android.build.api.dsl.ManagedVirtualDevice) { // A lower resolution device is used here for better emulator performance device = "Nexus One" apiLevel = 30 // Also use the AOSP ATD image for better emulator performance systemImageSource = "aosp-atd" } } } } namespace "com.example.android.testing.espresso.IdlingResourceSample" testNamespace "com.example.android.testing.espresso.IdlingResourceSample.test" lint { abortOnError false } } dependencies { // App dependencies implementation "androidx.annotation:annotation:" + rootProject.androidxAnnotationVersion implementation "com.google.guava:guava:" + rootProject.guavaVersion // Testing-only dependencies androidTestImplementation "androidx.test:core:" + rootProject.coreVersion androidTestImplementation "androidx.test.ext:junit:" + rootProject.extJUnitVersion androidTestImplementation "androidx.test:runner:" + rootProject.runnerVersion androidTestImplementation "androidx.test.espresso:espresso-core:" + rootProject.espressoVersion // Note that espresso-idling-resource is used in the code under test. implementation "androidx.test.espresso:espresso-idling-resource:" + rootProject.espressoVersion } ================================================ FILE: ui/espresso/IdlingResourceSample/app/src/androidTest/AndroidManifest.xml ================================================ ================================================ FILE: ui/espresso/IdlingResourceSample/app/src/androidTest/java/com/example/android/testing/espresso/IdlingResourceSample/ChangeTextBehaviorTest.java ================================================ /* * Copyright 2016, The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.example.android.testing.espresso.IdlingResourceSample; import static androidx.test.espresso.Espresso.onView; import static androidx.test.espresso.action.ViewActions.click; import static androidx.test.espresso.action.ViewActions.closeSoftKeyboard; import static androidx.test.espresso.action.ViewActions.typeText; import static androidx.test.espresso.assertion.ViewAssertions.matches; import static androidx.test.espresso.matcher.ViewMatchers.withId; import static androidx.test.espresso.matcher.ViewMatchers.withText; import androidx.test.core.app.ActivityScenario; import androidx.test.espresso.IdlingRegistry; import androidx.test.espresso.IdlingResource; import androidx.test.filters.LargeTest; import androidx.test.ext.junit.runners.AndroidJUnit4; import org.junit.After; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; /** * Same as Espresso's BasicSample, but with an Idling Resource to help with synchronization. */ @RunWith(AndroidJUnit4.class) @LargeTest public class ChangeTextBehaviorTest { private static final String STRING_TO_BE_TYPED = "Espresso"; private IdlingResource mIdlingResource; /** * Use {@link ActivityScenario to launch and get access to the activity. * {@link ActivityScenario#onActivity(ActivityScenario.ActivityAction)} provides a thread-safe * mechanism to access the activity. */ @Before public void registerIdlingResource() { ActivityScenario activityScenario = ActivityScenario.launch(MainActivity.class); activityScenario.onActivity(new ActivityScenario.ActivityAction() { @Override public void perform(MainActivity activity) { mIdlingResource = activity.getIdlingResource(); // To prove that the test fails, omit this call: IdlingRegistry.getInstance().register(mIdlingResource); } }); } @Test public void changeText_sameActivity() { // Type text and then press the button. onView(withId(R.id.editTextUserInput)) .perform(typeText(STRING_TO_BE_TYPED), closeSoftKeyboard()); onView(withId(R.id.changeTextBt)).perform(click()); // Check that the text was changed. onView(withId(R.id.textToBeChanged)).check(matches(withText(STRING_TO_BE_TYPED))); } @After public void unregisterIdlingResource() { if (mIdlingResource != null) { IdlingRegistry.getInstance().unregister(mIdlingResource); } } } ================================================ FILE: ui/espresso/IdlingResourceSample/app/src/main/AndroidManifest.xml ================================================ ================================================ FILE: ui/espresso/IdlingResourceSample/app/src/main/AppManifest.xml ================================================ ================================================ FILE: ui/espresso/IdlingResourceSample/app/src/main/java/com/example/android/testing/espresso/IdlingResourceSample/IdlingResource/SimpleIdlingResource.java ================================================ /* * Copyright 2016, The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.example.android.testing.espresso.IdlingResourceSample.IdlingResource; import androidx.annotation.Nullable; import androidx.test.espresso.IdlingResource; import java.util.concurrent.atomic.AtomicBoolean; /** * A very simple implementation of {@link IdlingResource}. *

* Consider using CountingIdlingResource from espresso-contrib package if you use this class from * multiple threads or need to keep a count of pending operations. */ public class SimpleIdlingResource implements IdlingResource { @Nullable private volatile ResourceCallback mCallback; // Idleness is controlled with this boolean. private AtomicBoolean mIsIdleNow = new AtomicBoolean(true); @Override public String getName() { return this.getClass().getName(); } @Override public boolean isIdleNow() { return mIsIdleNow.get(); } @Override public void registerIdleTransitionCallback(ResourceCallback callback) { mCallback = callback; } /** * Sets the new idle state, if isIdleNow is true, it pings the {@link ResourceCallback}. * @param isIdleNow false if there are pending operations, true if idle. */ public void setIdleState(boolean isIdleNow) { mIsIdleNow.set(isIdleNow); if (isIdleNow && mCallback != null) { mCallback.onTransitionToIdle(); } } } ================================================ FILE: ui/espresso/IdlingResourceSample/app/src/main/java/com/example/android/testing/espresso/IdlingResourceSample/MainActivity.java ================================================ /* * Copyright 2016, The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.example.android.testing.espresso.IdlingResourceSample; import android.app.Activity; import android.os.Bundle; import androidx.annotation.NonNull; import androidx.annotation.Nullable; import androidx.annotation.VisibleForTesting; import androidx.test.espresso.IdlingResource; import android.view.View; import android.widget.EditText; import android.widget.TextView; import com.example.android.testing.espresso.IdlingResourceSample.IdlingResource.SimpleIdlingResource; /** * Gets a text String from the user and displays it back after a while. */ public class MainActivity extends Activity implements View.OnClickListener, MessageDelayer.DelayerCallback { // The TextView used to display the message inside the Activity. private TextView mTextView; // The EditText where the user types the message. private EditText mEditText; // The Idling Resource which will be null in production. @Nullable private SimpleIdlingResource mIdlingResource; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); // Set the listeners for the buttons. findViewById(R.id.changeTextBt).setOnClickListener(this); mTextView = (TextView) findViewById(R.id.textToBeChanged); mEditText = (EditText) findViewById(R.id.editTextUserInput); } @Override public void onClick(View view) { // Get the text from the EditText view. final String text = mEditText.getText().toString(); if (view.getId() == R.id.changeTextBt) { // Set a temporary text. mTextView.setText(R.string.waiting_msg); // Submit the message to the delayer. MessageDelayer.processMessage(text, this, mIdlingResource); } } @Override public void onDone(String text) { // The delayer notifies the activity via a callback. mTextView.setText(text); } /** * Only called from test, creates and returns a new {@link SimpleIdlingResource}. */ @VisibleForTesting @NonNull public IdlingResource getIdlingResource() { if (mIdlingResource == null) { mIdlingResource = new SimpleIdlingResource(); } return mIdlingResource; } } ================================================ FILE: ui/espresso/IdlingResourceSample/app/src/main/java/com/example/android/testing/espresso/IdlingResourceSample/MessageDelayer.java ================================================ /* * Copyright 2016, The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.example.android.testing.espresso.IdlingResourceSample; import android.os.Handler; import androidx.annotation.Nullable; import androidx.test.espresso.IdlingResource; import com.example.android.testing.espresso.IdlingResourceSample.IdlingResource.SimpleIdlingResource; /** * Takes a String and returns it after a while via a callback. *

* This executes a long-running operation on a different thread that results in problems with * Espresso if an {@link IdlingResource} is not implemented and registered. */ class MessageDelayer { private static final int DELAY_MILLIS = 3000; interface DelayerCallback { void onDone(String text); } /** * Takes a String and returns it after {@link #DELAY_MILLIS} via a {@link DelayerCallback}. * @param message the String that will be returned via the callback * @param callback used to notify the caller asynchronously */ static void processMessage(final String message, final DelayerCallback callback, @Nullable final SimpleIdlingResource idlingResource) { // The IdlingResource is null in production. if (idlingResource != null) { idlingResource.setIdleState(false); } // Delay the execution, return message via callback. Handler handler = new Handler(); handler.postDelayed(new Runnable() { @Override public void run() { if (callback != null) { callback.onDone(message); if (idlingResource != null) { idlingResource.setIdleState(true); } } } }, DELAY_MILLIS); } } ================================================ FILE: ui/espresso/IdlingResourceSample/app/src/main/res/layout/activity_main.xml ================================================