diff --git a/.bazelrc b/.bazelrc new file mode 100644 index 000000000..d484f9da4 --- /dev/null +++ b/.bazelrc @@ -0,0 +1,74 @@ +# 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 diff --git a/.github/ci-gradle.properties b/.github/ci-gradle.properties new file mode 100644 index 000000000..e69de29bb diff --git a/.github/workflows/composescreenshot.yml b/.github/workflows/composescreenshot.yml new file mode 100644 index 000000000..c717f8305 --- /dev/null +++ b/.github/workflows/composescreenshot.yml @@ -0,0 +1,24 @@ +# Workflow name +name: Compose Preview Screenshot +on: + # 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 diff --git a/.github/workflows/copy-branch.yml b/.github/workflows/copy-branch.yml new file mode 100644 index 000000000..f8f8572d9 --- /dev/null +++ b/.github/workflows/copy-branch.yml @@ -0,0 +1,31 @@ +# 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: + 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 diff --git a/.github/workflows/gradle-wrapper-validation.yml b/.github/workflows/gradle-wrapper-validation.yml new file mode 100644 index 000000000..41735cbf2 --- /dev/null +++ b/.github/workflows/gradle-wrapper-validation.yml @@ -0,0 +1,16 @@ +name: Validate Gradle Wrapper + +on: + 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 diff --git a/.github/workflows/test-all.yml b/.github/workflows/test-all.yml new file mode 100644 index 000000000..2c0b5d626 --- /dev/null +++ b/.github/workflows/test-all.yml @@ -0,0 +1,43 @@ +# Workflow name +name: Build + Test all +on: + # 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' diff --git a/.gitignore b/.gitignore index 28c0a8191..2e822ca17 100644 --- a/.gitignore +++ b/.gitignore @@ -3,3 +3,9 @@ local.properties build .gradle +# Eclipse project files +.project +.settings/ +.classpath +bazel-* +.DS_Store diff --git a/BUILD.bazel b/BUILD.bazel new file mode 100644 index 000000000..114654e5c --- /dev/null +++ b/BUILD.bazel @@ -0,0 +1,54 @@ +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" + } +""", +) diff --git a/CONTRIB.md b/CONTRIB.md deleted file mode 100644 index fe1f58833..000000000 --- a/CONTRIB.md +++ /dev/null @@ -1,34 +0,0 @@ -# How to become a contributor and submit your own code - -## 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). - -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. diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index fe1f58833..f282da6a4 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -1,5 +1,23 @@ # 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 @@ -13,6 +31,7 @@ Please fill out either the individual or corporate Contributor License Agreement * 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 diff --git a/README.md b/README.md index 33eccb8aa..09c9728d1 100644 --- a/README.md +++ b/README.md @@ -1,23 +1,134 @@ 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 v21 -- Android Build Tools v21.1.2 -- Android Support Repository +- 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 connectedCheck` to run the tests on a connected emulator or device. +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 ------- @@ -33,7 +144,7 @@ submitting a pull request through GitHub. Please see CONTRIBUTING.md for more de License ------- -Copyright 2014 The Android Open Source Project, Inc. +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 @@ -49,5 +160,3 @@ 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. - - diff --git a/WORKSPACE b/WORKSPACE new file mode 100644 index 000000000..868cb6fde --- /dev/null +++ b/WORKSPACE @@ -0,0 +1,115 @@ +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") diff --git a/bazelci/buildkite-pipeline.yml b/bazelci/buildkite-pipeline.yml new file mode 100644 index 000000000..89474fcfe --- /dev/null +++ b/bazelci/buildkite-pipeline.yml @@ -0,0 +1,138 @@ +# 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" + diff --git a/build.gradle b/build.gradle deleted file mode 100644 index e7e03415f..000000000 --- a/build.gradle +++ /dev/null @@ -1,42 +0,0 @@ -// Top-level build file where you can add configuration options common to all sub-projects/modules. - -buildscript { - repositories { - jcenter() - } - dependencies { - classpath 'com.android.tools.build:gradle:1.0.0' - - // NOTE: Do not place your application dependencies here; they belong - // in the individual module build.gradle files - } -} - -allprojects { - repositories { - jcenter() - } - - apply plugin: 'findbugs' - - task findbugs(type: FindBugs) { - ignoreFailures = true - effort = "max" - reportLevel = "high" - //excludeFilter = new File("${project.rootDir}/config/quality/findbugs/findbugs-filter.xml") - classes = files("$project.buildDir/intermediates/classes/") - - source 'src' - include '**/*.java' - exclude '**/gen/**' - - reports { - xml { - destination "$project.buildDir/reports/findbugs/findbugs.xml" - xml.withMessages true - } - } - - classpath = files() - } -} diff --git a/common_defs.bzl b/common_defs.bzl new file mode 100644 index 000000000..6e4f4f3b5 --- /dev/null +++ b/common_defs.bzl @@ -0,0 +1,15 @@ +# 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" diff --git a/espresso/BasicSample/app/build.gradle b/espresso/BasicSample/app/build.gradle deleted file mode 100644 index 815e2f945..000000000 --- a/espresso/BasicSample/app/build.gradle +++ /dev/null @@ -1,32 +0,0 @@ -apply plugin: 'com.android.application' - -android { - compileSdkVersion 21 - buildToolsVersion '21.1.2' - - defaultConfig { - applicationId "com.example.android.testing.espresso.BasicSample" - minSdkVersion 10 - targetSdkVersion 21 - versionCode 1 - versionName "1.0" - - testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" - } - packagingOptions { - exclude 'LICENSE.txt' - } - lintOptions { - abortOnError false - } -} - -dependencies { - // App dependencies - compile 'com.android.support:support-annotations:21.0.3' - compile 'com.google.guava:guava:18.0' - - // Testing-only dependencies - androidTestCompile 'com.android.support.test:testing-support-lib:0.1' - androidTestCompile 'com.android.support.test.espresso:espresso-core:2.0' -} diff --git a/espresso/BasicSample/build.gradle b/espresso/BasicSample/build.gradle deleted file mode 100644 index 6356aabdc..000000000 --- a/espresso/BasicSample/build.gradle +++ /dev/null @@ -1,19 +0,0 @@ -// Top-level build file where you can add configuration options common to all sub-projects/modules. - -buildscript { - repositories { - jcenter() - } - dependencies { - classpath 'com.android.tools.build:gradle:1.0.0' - - // NOTE: Do not place your application dependencies here; they belong - // in the individual module build.gradle files - } -} - -allprojects { - repositories { - jcenter() - } -} diff --git a/espresso/BasicSample/gradle/wrapper/gradle-wrapper.jar b/espresso/BasicSample/gradle/wrapper/gradle-wrapper.jar deleted file mode 100644 index 8c0fb64a8..000000000 Binary files a/espresso/BasicSample/gradle/wrapper/gradle-wrapper.jar and /dev/null differ diff --git a/espresso/BasicSample/gradle/wrapper/gradle-wrapper.properties b/espresso/BasicSample/gradle/wrapper/gradle-wrapper.properties deleted file mode 100644 index 0ed71dbdb..000000000 --- a/espresso/BasicSample/gradle/wrapper/gradle-wrapper.properties +++ /dev/null @@ -1,6 +0,0 @@ -#Wed Nov 05 14:10:42 GMT 2014 -distributionBase=GRADLE_USER_HOME -distributionPath=wrapper/dists -zipStoreBase=GRADLE_USER_HOME -zipStorePath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-2.2.1-all.zip diff --git a/espresso/BasicSampleBundled/.classpath b/espresso/BasicSampleBundled/.classpath deleted file mode 100644 index 2ed571346..000000000 --- a/espresso/BasicSampleBundled/.classpath +++ /dev/null @@ -1,11 +0,0 @@ - - - - - - - - - - - diff --git a/espresso/BasicSampleBundled/.gitignore b/espresso/BasicSampleBundled/.gitignore deleted file mode 100644 index e614fbbef..000000000 --- a/espresso/BasicSampleBundled/.gitignore +++ /dev/null @@ -1,2 +0,0 @@ -bin -gen diff --git a/espresso/BasicSampleBundled/.project b/espresso/BasicSampleBundled/.project deleted file mode 100644 index 71a8acadd..000000000 --- a/espresso/BasicSampleBundled/.project +++ /dev/null @@ -1,33 +0,0 @@ - - - BasicSampleBundled - - - - - - com.android.ide.eclipse.adt.ResourceManagerBuilder - - - - - com.android.ide.eclipse.adt.PreCompilerBuilder - - - - - org.eclipse.jdt.core.javabuilder - - - - - com.android.ide.eclipse.adt.ApkBuilder - - - - - - com.android.ide.eclipse.adt.AndroidNature - org.eclipse.jdt.core.javanature - - diff --git a/espresso/BasicSampleBundled/AndroidManifest.xml b/espresso/BasicSampleBundled/AndroidManifest.xml deleted file mode 100644 index 3fed47e1e..000000000 --- a/espresso/BasicSampleBundled/AndroidManifest.xml +++ /dev/null @@ -1,32 +0,0 @@ - - - - - - - - - - - - - - - - - - - diff --git a/espresso/BasicSampleBundled/README.md b/espresso/BasicSampleBundled/README.md deleted file mode 100644 index b965e88e4..000000000 --- a/espresso/BasicSampleBundled/README.md +++ /dev/null @@ -1,25 +0,0 @@ -# Basic sample for Espresso using static JAR files - -*If you are using Espresso with Eclipse, try this sample first.* - -This project uses Eclipse and ADT to build and run the tests. - -1. Download the project code, preferably using `git clone`. -1. Check out the static JAR files required to run the Espresso tests in the libs/ folder of the project -1. Run the ./remove_license.sh script to remove duplicated LICENSE.txt files. This step is required because some of the test dependencies contain LICENSE.txt files which result in this build error: -"Error generating final archive: Found duplicate file for APK: LICENSE.txt". -The problem is that the same LICENSE.TXT file is found multiple times and AAPT does not know how to resolve this conflict. -1. Check out the relevant code: - * The application under test is located in `src/` - * Tests are in `tests/` -1. Create the test configuration with a custom runner: `android.support.test.runner.AndroidJUnitRunner` - * Open *Run* menu | *Run Configurations* - * Click on Android JUnit Test - * Add a new configuration by pressing the "new launch configuration" button - * Select your project by clicking the "Browse" button - * Add a *Specific instrumentation runner*: `android.support.test.runner.AndroidJUnitRunner` -1. Connect a device or start an emulator - * Turn animations off [link link] -1. Run the newly created configuration - -The application will be started on the device/emulator and a series of actions will be performed automatically. diff --git a/espresso/BasicSampleBundled/ic_launcher-web.png b/espresso/BasicSampleBundled/ic_launcher-web.png deleted file mode 100644 index 745d2e70b..000000000 Binary files a/espresso/BasicSampleBundled/ic_launcher-web.png and /dev/null differ diff --git a/espresso/BasicSampleBundled/libs/android-support-v4.jar b/espresso/BasicSampleBundled/libs/android-support-v4.jar deleted file mode 100644 index 4ebdaa9ed..000000000 Binary files a/espresso/BasicSampleBundled/libs/android-support-v4.jar and /dev/null differ diff --git a/espresso/BasicSampleBundled/libs/dagger-1.2.1.jar b/espresso/BasicSampleBundled/libs/dagger-1.2.1.jar deleted file mode 100644 index 90d950993..000000000 Binary files a/espresso/BasicSampleBundled/libs/dagger-1.2.1.jar and /dev/null differ diff --git a/espresso/BasicSampleBundled/libs/dagger-compiler-1.2.1.jar b/espresso/BasicSampleBundled/libs/dagger-compiler-1.2.1.jar deleted file mode 100644 index f2aa56df7..000000000 Binary files a/espresso/BasicSampleBundled/libs/dagger-compiler-1.2.1.jar and /dev/null differ diff --git a/espresso/BasicSampleBundled/libs/espresso-contrib-release-2.0.jar b/espresso/BasicSampleBundled/libs/espresso-contrib-release-2.0.jar deleted file mode 100644 index b601f738d..000000000 Binary files a/espresso/BasicSampleBundled/libs/espresso-contrib-release-2.0.jar and /dev/null differ diff --git a/espresso/BasicSampleBundled/libs/espresso-core-release-2.0.jar b/espresso/BasicSampleBundled/libs/espresso-core-release-2.0.jar deleted file mode 100644 index 0829e651c..000000000 Binary files a/espresso/BasicSampleBundled/libs/espresso-core-release-2.0.jar and /dev/null differ diff --git a/espresso/BasicSampleBundled/libs/espresso-idling-resource-release-2.0.jar b/espresso/BasicSampleBundled/libs/espresso-idling-resource-release-2.0.jar deleted file mode 100644 index b82b525c0..000000000 Binary files a/espresso/BasicSampleBundled/libs/espresso-idling-resource-release-2.0.jar and /dev/null differ diff --git a/espresso/BasicSampleBundled/libs/guava-14.0.1.jar b/espresso/BasicSampleBundled/libs/guava-14.0.1.jar deleted file mode 100644 index 3a3d9258e..000000000 Binary files a/espresso/BasicSampleBundled/libs/guava-14.0.1.jar and /dev/null differ diff --git a/espresso/BasicSampleBundled/libs/hamcrest-core-1.1.jar b/espresso/BasicSampleBundled/libs/hamcrest-core-1.1.jar deleted file mode 100644 index e5149be76..000000000 Binary files a/espresso/BasicSampleBundled/libs/hamcrest-core-1.1.jar and /dev/null differ diff --git a/espresso/BasicSampleBundled/libs/hamcrest-integration-1.1.jar b/espresso/BasicSampleBundled/libs/hamcrest-integration-1.1.jar deleted file mode 100644 index 2c718875b..000000000 Binary files a/espresso/BasicSampleBundled/libs/hamcrest-integration-1.1.jar and /dev/null differ diff --git a/espresso/BasicSampleBundled/libs/hamcrest-library-1.1.jar b/espresso/BasicSampleBundled/libs/hamcrest-library-1.1.jar deleted file mode 100644 index 8e9e173a3..000000000 Binary files a/espresso/BasicSampleBundled/libs/hamcrest-library-1.1.jar and /dev/null differ diff --git a/espresso/BasicSampleBundled/libs/javawriter-2.1.1.jar b/espresso/BasicSampleBundled/libs/javawriter-2.1.1.jar deleted file mode 100644 index 62ad1d805..000000000 Binary files a/espresso/BasicSampleBundled/libs/javawriter-2.1.1.jar and /dev/null differ diff --git a/espresso/BasicSampleBundled/libs/javax.annotation-api-1.2.jar b/espresso/BasicSampleBundled/libs/javax.annotation-api-1.2.jar deleted file mode 100644 index 9ab39ffa4..000000000 Binary files a/espresso/BasicSampleBundled/libs/javax.annotation-api-1.2.jar and /dev/null differ diff --git a/espresso/BasicSampleBundled/libs/javax.inject-1.jar b/espresso/BasicSampleBundled/libs/javax.inject-1.jar deleted file mode 100644 index b2a9d0bf7..000000000 Binary files a/espresso/BasicSampleBundled/libs/javax.inject-1.jar and /dev/null differ diff --git a/espresso/BasicSampleBundled/libs/jsr305-1.3.9.jar b/espresso/BasicSampleBundled/libs/jsr305-1.3.9.jar deleted file mode 100644 index a9afc6619..000000000 Binary files a/espresso/BasicSampleBundled/libs/jsr305-1.3.9.jar and /dev/null differ diff --git a/espresso/BasicSampleBundled/libs/junit-dep-4.10.jar b/espresso/BasicSampleBundled/libs/junit-dep-4.10.jar deleted file mode 100644 index 32209cb13..000000000 Binary files a/espresso/BasicSampleBundled/libs/junit-dep-4.10.jar and /dev/null differ diff --git a/espresso/BasicSampleBundled/libs/testing-support-lib-release-0.1.jar b/espresso/BasicSampleBundled/libs/testing-support-lib-release-0.1.jar deleted file mode 100644 index 42af7df7e..000000000 Binary files a/espresso/BasicSampleBundled/libs/testing-support-lib-release-0.1.jar and /dev/null differ diff --git a/espresso/BasicSampleBundled/proguard-project.txt b/espresso/BasicSampleBundled/proguard-project.txt deleted file mode 100644 index f2fe1559a..000000000 --- a/espresso/BasicSampleBundled/proguard-project.txt +++ /dev/null @@ -1,20 +0,0 @@ -# To enable ProGuard in your project, edit project.properties -# to define the proguard.config property as described in that file. -# -# Add project specific ProGuard rules here. -# By default, the flags in this file are appended to flags specified -# in ${sdk.dir}/tools/proguard/proguard-android.txt -# You can edit the include path and order by changing the ProGuard -# include property in project.properties. -# -# For more details, see -# http://developer.android.com/guide/developing/tools/proguard.html - -# Add any project specific keep options here: - -# If your project uses WebView with JS, uncomment the following -# and specify the fully qualified class name to the JavaScript interface -# class: -#-keepclassmembers class fqcn.of.javascript.interface.for.webview { -# public *; -#} diff --git a/espresso/BasicSampleBundled/project.properties b/espresso/BasicSampleBundled/project.properties deleted file mode 100644 index 6e18427a4..000000000 --- a/espresso/BasicSampleBundled/project.properties +++ /dev/null @@ -1,14 +0,0 @@ -# This file is automatically generated by Android Tools. -# Do not modify this file -- YOUR CHANGES WILL BE ERASED! -# -# This file must be checked in Version Control Systems. -# -# To customize properties used by the Ant build system edit -# "ant.properties", and override values to adapt the script to your -# project structure. -# -# To enable ProGuard to shrink and obfuscate your code, uncomment this (available properties: sdk.dir, user.home): -#proguard.config=${sdk.dir}/tools/proguard/proguard-android.txt:proguard-project.txt - -# Project target. -target=android-21 diff --git a/espresso/BasicSampleBundled/remove_license.sh b/espresso/BasicSampleBundled/remove_license.sh deleted file mode 100755 index 99cb55b84..000000000 --- a/espresso/BasicSampleBundled/remove_license.sh +++ /dev/null @@ -1,5 +0,0 @@ -zip -d libs/hamcrest-core-1.1.jar LICENSE.txt -zip -d libs/hamcrest-library-1.1.jar LICENSE.txt -zip -d libs/hamcrest-integration-1.1.jar LICENSE.txt -zip -d libs/junit-dep-4.10.jar LICENSE.txt - diff --git a/espresso/BasicSampleBundled/res/drawable-hdpi/ic_launcher.png b/espresso/BasicSampleBundled/res/drawable-hdpi/ic_launcher.png deleted file mode 100644 index 5a06f0fda..000000000 Binary files a/espresso/BasicSampleBundled/res/drawable-hdpi/ic_launcher.png and /dev/null differ diff --git a/espresso/BasicSampleBundled/res/drawable-mdpi/ic_launcher.png b/espresso/BasicSampleBundled/res/drawable-mdpi/ic_launcher.png deleted file mode 100644 index 1758c24c1..000000000 Binary files a/espresso/BasicSampleBundled/res/drawable-mdpi/ic_launcher.png and /dev/null differ diff --git a/espresso/BasicSampleBundled/res/drawable-xhdpi/ic_launcher.png b/espresso/BasicSampleBundled/res/drawable-xhdpi/ic_launcher.png deleted file mode 100644 index fc92a5613..000000000 Binary files a/espresso/BasicSampleBundled/res/drawable-xhdpi/ic_launcher.png and /dev/null differ diff --git a/espresso/BasicSampleBundled/res/drawable-xxhdpi/ic_launcher.png b/espresso/BasicSampleBundled/res/drawable-xxhdpi/ic_launcher.png deleted file mode 100644 index 9837c49b8..000000000 Binary files a/espresso/BasicSampleBundled/res/drawable-xxhdpi/ic_launcher.png and /dev/null differ diff --git a/espresso/BasicSampleBundled/res/values-v11/styles.xml b/espresso/BasicSampleBundled/res/values-v11/styles.xml deleted file mode 100644 index 51e666758..000000000 --- a/espresso/BasicSampleBundled/res/values-v11/styles.xml +++ /dev/null @@ -1,11 +0,0 @@ - - - - - - diff --git a/espresso/BasicSampleBundled/res/values-v14/styles.xml b/espresso/BasicSampleBundled/res/values-v14/styles.xml deleted file mode 100644 index 9b9dee210..000000000 --- a/espresso/BasicSampleBundled/res/values-v14/styles.xml +++ /dev/null @@ -1,12 +0,0 @@ - - - - - - diff --git a/espresso/BasicSampleBundled/tests/com/example/android/testing/espresso/basicsamplebundled/tests/ChangeTextBehaviorTest.java b/espresso/BasicSampleBundled/tests/com/example/android/testing/espresso/basicsamplebundled/tests/ChangeTextBehaviorTest.java deleted file mode 100644 index c327cfcf0..000000000 --- a/espresso/BasicSampleBundled/tests/com/example/android/testing/espresso/basicsamplebundled/tests/ChangeTextBehaviorTest.java +++ /dev/null @@ -1,78 +0,0 @@ -/* - * 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. - */ - -package com.example.android.testing.espresso.basicsamplebundled.tests; - -import static android.support.test.espresso.Espresso.onView; -import static android.support.test.espresso.action.ViewActions.click; -import static android.support.test.espresso.action.ViewActions.closeSoftKeyboard; -import static android.support.test.espresso.action.ViewActions.typeText; -import static android.support.test.espresso.assertion.ViewAssertions.matches; -import static android.support.test.espresso.matcher.ViewMatchers.withId; -import static android.support.test.espresso.matcher.ViewMatchers.withText; - -import android.app.Activity; -import android.test.ActivityInstrumentationTestCase2; -import android.support.test.espresso.action.ViewActions; -import android.support.test.espresso.matcher.ViewMatchers; - -import com.example.android.testing.espresso.basicsamplebundled.MainActivity; -import com.example.android.testing.espresso.basicsamplebundled.R; - - -/** - * Basic tests showcasing simple view matchers and actions like {@link ViewMatchers#withId}, - * {@link ViewActions#click} and {@link ViewActions#typeText}. - *

- * Note that there is no need to tell Espresso that a view is in a different {@link Activity}. - *

- */ -public class ChangeTextBehaviorTest extends ActivityInstrumentationTestCase2 { - - public static final String STRING_TO_BE_TYPED = "Espresso"; - - public ChangeTextBehaviorTest() { - super(MainActivity.class); - } - - @Override - protected void setUp() throws Exception { - super.setUp(); - // For each test method invocation, the Activity will not actually be created - // until the first time this method is called. - getActivity(); - } - - public void testChangeText_sameActivity() { - // Type text and then press the button. - onView(ViewMatchers.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))); - } - - public void testChangeText_newActivity() { - // Type text and then press the button. - onView(withId(R.id.editTextUserInput)).perform(typeText(STRING_TO_BE_TYPED), - closeSoftKeyboard()); - onView(withId(R.id.activityChangeTextBtn)).perform(click()); - - // This view is in a different Activity, no need to tell Espresso. - onView(withId(R.id.show_text_view)).check(matches(withText(STRING_TO_BE_TYPED))); - } -} \ No newline at end of file diff --git a/espresso/CustomMatcherSample/app/build.gradle b/espresso/CustomMatcherSample/app/build.gradle deleted file mode 100644 index a9778f1b5..000000000 --- a/espresso/CustomMatcherSample/app/build.gradle +++ /dev/null @@ -1,41 +0,0 @@ -apply plugin: 'com.android.application' - -android { - compileSdkVersion 21 - buildToolsVersion "21.1.2" - - defaultConfig { - applicationId "com.example.android.testing.espresso.CustomMatcherSample" - minSdkVersion 10 - targetSdkVersion 21 - versionCode 1 - versionName "1.0" - - testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" - } - - buildTypes { - release { - minifyEnabled false - proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' - } - } - - packagingOptions { - exclude 'LICENSE.txt' - } - - lintOptions { - abortOnError false - } -} - -dependencies { - // App dependencies - compile 'com.android.support:support-annotations:21.0.3' - compile 'com.google.guava:guava:18.0' - - // Testing-only dependencies - androidTestCompile 'com.android.support.test:testing-support-lib:0.1' - androidTestCompile 'com.android.support.test.espresso:espresso-core:2.0' -} diff --git a/espresso/CustomMatcherSample/build.gradle b/espresso/CustomMatcherSample/build.gradle deleted file mode 100644 index 6356aabdc..000000000 --- a/espresso/CustomMatcherSample/build.gradle +++ /dev/null @@ -1,19 +0,0 @@ -// Top-level build file where you can add configuration options common to all sub-projects/modules. - -buildscript { - repositories { - jcenter() - } - dependencies { - classpath 'com.android.tools.build:gradle:1.0.0' - - // NOTE: Do not place your application dependencies here; they belong - // in the individual module build.gradle files - } -} - -allprojects { - repositories { - jcenter() - } -} diff --git a/espresso/CustomMatcherSample/gradle/wrapper/gradle-wrapper.jar b/espresso/CustomMatcherSample/gradle/wrapper/gradle-wrapper.jar deleted file mode 100644 index 8c0fb64a8..000000000 Binary files a/espresso/CustomMatcherSample/gradle/wrapper/gradle-wrapper.jar and /dev/null differ diff --git a/espresso/DataAdapterSample/app/build.gradle b/espresso/DataAdapterSample/app/build.gradle deleted file mode 100644 index 19f9c904e..000000000 --- a/espresso/DataAdapterSample/app/build.gradle +++ /dev/null @@ -1,31 +0,0 @@ - -apply plugin: 'com.android.application' - -android { - compileSdkVersion 21 - buildToolsVersion '21.1.2' - - defaultConfig { - applicationId "com.example.android.testing.espresso.DataAdapterSample" - minSdkVersion 10 - targetSdkVersion 21 - versionCode 1 - versionName "1.0" - testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" - - } - packagingOptions { - exclude 'LICENSE.txt' - } -} - -dependencies { - // App dependencies - compile 'com.android.support:support-annotations:21.0.3' - compile 'com.google.guava:guava:18.0' - - // Testing-only dependencies - androidTestCompile 'com.android.support.test:testing-support-lib:0.1' - androidTestCompile 'com.android.support.test.espresso:espresso-core:2.0' - -} diff --git a/espresso/DataAdapterSample/build.gradle b/espresso/DataAdapterSample/build.gradle deleted file mode 100644 index 6356aabdc..000000000 --- a/espresso/DataAdapterSample/build.gradle +++ /dev/null @@ -1,19 +0,0 @@ -// Top-level build file where you can add configuration options common to all sub-projects/modules. - -buildscript { - repositories { - jcenter() - } - dependencies { - classpath 'com.android.tools.build:gradle:1.0.0' - - // NOTE: Do not place your application dependencies here; they belong - // in the individual module build.gradle files - } -} - -allprojects { - repositories { - jcenter() - } -} diff --git a/espresso/DataAdapterSample/gradle/wrapper/gradle-wrapper.jar b/espresso/DataAdapterSample/gradle/wrapper/gradle-wrapper.jar deleted file mode 100644 index 8c0fb64a8..000000000 Binary files a/espresso/DataAdapterSample/gradle/wrapper/gradle-wrapper.jar and /dev/null differ diff --git a/espresso/MultiWindowSample/app/build.gradle b/espresso/MultiWindowSample/app/build.gradle deleted file mode 100644 index 7e3d73bd8..000000000 --- a/espresso/MultiWindowSample/app/build.gradle +++ /dev/null @@ -1,42 +0,0 @@ - -apply plugin: 'com.android.application' - -android { - compileSdkVersion 21 - buildToolsVersion '21.1.2' - - defaultConfig { - applicationId "com.example.android.testing.espresso.MultiWindowSample" - minSdkVersion 10 - targetSdkVersion 21 - versionCode 1 - versionName "1.0" - testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" - - } - - buildTypes { - release { - minifyEnabled false - proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' - } - } - - packagingOptions { - exclude 'LICENSE.txt' - } - - lintOptions { - abortOnError false - } -} - -dependencies { - // App dependencies - compile 'com.android.support:support-annotations:21.0.3' - compile 'com.google.guava:guava:18.0' - - // Testing-only dependencies - androidTestCompile 'com.android.support.test:testing-support-lib:0.1' - androidTestCompile 'com.android.support.test.espresso:espresso-core:2.0' -} diff --git a/espresso/MultiWindowSample/build.gradle b/espresso/MultiWindowSample/build.gradle deleted file mode 100644 index 6356aabdc..000000000 --- a/espresso/MultiWindowSample/build.gradle +++ /dev/null @@ -1,19 +0,0 @@ -// Top-level build file where you can add configuration options common to all sub-projects/modules. - -buildscript { - repositories { - jcenter() - } - dependencies { - classpath 'com.android.tools.build:gradle:1.0.0' - - // NOTE: Do not place your application dependencies here; they belong - // in the individual module build.gradle files - } -} - -allprojects { - repositories { - jcenter() - } -} diff --git a/espresso/MultiWindowSample/gradle/wrapper/gradle-wrapper.jar b/espresso/MultiWindowSample/gradle/wrapper/gradle-wrapper.jar deleted file mode 100644 index 8c0fb64a8..000000000 Binary files a/espresso/MultiWindowSample/gradle/wrapper/gradle-wrapper.jar and /dev/null differ diff --git a/gradle/wrapper/gradle-wrapper.jar b/gradle/wrapper/gradle-wrapper.jar deleted file mode 100644 index 8c0fb64a8..000000000 Binary files a/gradle/wrapper/gradle-wrapper.jar and /dev/null differ diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties deleted file mode 100644 index 0c71e760d..000000000 --- a/gradle/wrapper/gradle-wrapper.properties +++ /dev/null @@ -1,6 +0,0 @@ -#Wed Apr 10 15:27:10 PDT 2013 -distributionBase=GRADLE_USER_HOME -distributionPath=wrapper/dists -zipStoreBase=GRADLE_USER_HOME -zipStorePath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-2.2.1-all.zip diff --git a/gradlew b/gradlew deleted file mode 100755 index 91a7e269e..000000000 --- a/gradlew +++ /dev/null @@ -1,164 +0,0 @@ -#!/usr/bin/env bash - -############################################################################## -## -## Gradle start up script for UN*X -## -############################################################################## - -# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. -DEFAULT_JVM_OPTS="" - -APP_NAME="Gradle" -APP_BASE_NAME=`basename "$0"` - -# 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 -case "`uname`" in - CYGWIN* ) - cygwin=true - ;; - Darwin* ) - darwin=true - ;; - MINGW* ) - msys=true - ;; -esac - -# For Cygwin, ensure paths are in UNIX format before anything is touched. -if $cygwin ; then - [ -n "$JAVA_HOME" ] && JAVA_HOME=`cygpath --unix "$JAVA_HOME"` -fi - -# 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\"`/" >&- -APP_HOME="`pwd -P`" -cd "$SAVED" >&- - -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" ] ; 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"` - - # 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 - -# Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules -function splitJvmOpts() { - JVM_OPTS=("$@") -} -eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS -JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME" - -exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@" diff --git a/espresso/BasicSample/.gitignore b/integration/ServiceTestRuleSample/.gitignore similarity index 100% rename from espresso/BasicSample/.gitignore rename to integration/ServiceTestRuleSample/.gitignore diff --git a/integration/ServiceTestRuleSample/README.md b/integration/ServiceTestRuleSample/README.md new file mode 100644 index 000000000..21c8a9d71 --- /dev/null +++ b/integration/ServiceTestRuleSample/README.md @@ -0,0 +1,25 @@ +# 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. diff --git a/integration/ServiceTestRuleSample/app/build.gradle b/integration/ServiceTestRuleSample/app/build.gradle new file mode 100644 index 000000000..5d2f7c613 --- /dev/null +++ b/integration/ServiceTestRuleSample/app/build.gradle @@ -0,0 +1,42 @@ +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; +} diff --git a/integration/ServiceTestRuleSample/app/src/androidTest/java/com/example/android/testing/ServiceTestRuleSample/LocalServiceTest.java b/integration/ServiceTestRuleSample/app/src/androidTest/java/com/example/android/testing/ServiceTestRuleSample/LocalServiceTest.java new file mode 100644 index 000000000..d81362862 --- /dev/null +++ b/integration/ServiceTestRuleSample/app/src/androidTest/java/com/example/android/testing/ServiceTestRuleSample/LocalServiceTest.java @@ -0,0 +1,77 @@ +/* + * 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))); + } +} diff --git a/integration/ServiceTestRuleSample/app/src/main/AndroidManifest.xml b/integration/ServiceTestRuleSample/app/src/main/AndroidManifest.xml new file mode 100644 index 000000000..5dc076f8c --- /dev/null +++ b/integration/ServiceTestRuleSample/app/src/main/AndroidManifest.xml @@ -0,0 +1,28 @@ + + + + + + + + + + + diff --git a/integration/ServiceTestRuleSample/app/src/main/java/com/example/android/testing/ServiceTestRuleSample/LocalService.java b/integration/ServiceTestRuleSample/app/src/main/java/com/example/android/testing/ServiceTestRuleSample/LocalService.java new file mode 100644 index 000000000..3eb0caef2 --- /dev/null +++ b/integration/ServiceTestRuleSample/app/src/main/java/com/example/android/testing/ServiceTestRuleSample/LocalService.java @@ -0,0 +1,68 @@ +/* + * 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); + } +} diff --git a/integration/ServiceTestRuleSample/app/src/main/res/mipmap-hdpi/ic_launcher.png b/integration/ServiceTestRuleSample/app/src/main/res/mipmap-hdpi/ic_launcher.png new file mode 100644 index 000000000..52b03d09f Binary files /dev/null and b/integration/ServiceTestRuleSample/app/src/main/res/mipmap-hdpi/ic_launcher.png differ diff --git a/integration/ServiceTestRuleSample/app/src/main/res/mipmap-mdpi/ic_launcher.png b/integration/ServiceTestRuleSample/app/src/main/res/mipmap-mdpi/ic_launcher.png new file mode 100644 index 000000000..a54984340 Binary files /dev/null and b/integration/ServiceTestRuleSample/app/src/main/res/mipmap-mdpi/ic_launcher.png differ diff --git a/integration/ServiceTestRuleSample/app/src/main/res/mipmap-xhdpi/ic_launcher.png b/integration/ServiceTestRuleSample/app/src/main/res/mipmap-xhdpi/ic_launcher.png new file mode 100644 index 000000000..77f72db4f Binary files /dev/null and b/integration/ServiceTestRuleSample/app/src/main/res/mipmap-xhdpi/ic_launcher.png differ diff --git a/integration/ServiceTestRuleSample/app/src/main/res/mipmap-xxhdpi/ic_launcher.png b/integration/ServiceTestRuleSample/app/src/main/res/mipmap-xxhdpi/ic_launcher.png new file mode 100644 index 000000000..b160e33dc Binary files /dev/null and b/integration/ServiceTestRuleSample/app/src/main/res/mipmap-xxhdpi/ic_launcher.png differ diff --git a/integration/ServiceTestRuleSample/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png b/integration/ServiceTestRuleSample/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png new file mode 100644 index 000000000..4c98df212 Binary files /dev/null and b/integration/ServiceTestRuleSample/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png differ diff --git a/integration/ServiceTestRuleSample/app/src/main/res/values-v13/styles.xml b/integration/ServiceTestRuleSample/app/src/main/res/values-v13/styles.xml new file mode 100644 index 000000000..7e86bfa57 --- /dev/null +++ b/integration/ServiceTestRuleSample/app/src/main/res/values-v13/styles.xml @@ -0,0 +1,20 @@ + + + + +