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 293b1b80f..2e822ca17 100644 --- a/.gitignore +++ b/.gitignore @@ -7,3 +7,5 @@ build .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/CONTRIBUTING.md b/CONTRIBUTING.md index 7b86f95d7..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 diff --git a/README.md b/README.md index fa8b6aeb8..09c9728d1 100644 --- a/README.md +++ b/README.md @@ -1,15 +1,58 @@ 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 v22 -- Android Build Tools v22 -- Android Support Repository rev15 +- Android SDK v28 +- Android Build Tools v28.03 Getting Started --------------- @@ -21,6 +64,71 @@ These samples use the Gradle build system. To build a project, enter the project 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 ------- @@ -52,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 b061b701d..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.2.3' - - // 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/downloads/Espresso Cheat Sheet Master.pdf b/downloads/Espresso Cheat Sheet Master.pdf deleted file mode 100644 index de3c2074a..000000000 Binary files a/downloads/Espresso Cheat Sheet Master.pdf and /dev/null differ diff --git a/downloads/Espresso Cheat Sheet Master.png b/downloads/Espresso Cheat Sheet Master.png deleted file mode 100644 index f53b5c0e7..000000000 Binary files a/downloads/Espresso Cheat Sheet Master.png and /dev/null differ diff --git a/downloads/espresso-cheat-sheet-2.1.0.pdf b/downloads/espresso-cheat-sheet-2.1.0.pdf deleted file mode 100644 index de3c2074a..000000000 Binary files a/downloads/espresso-cheat-sheet-2.1.0.pdf and /dev/null differ diff --git a/downloads/espresso-cheat-sheet-2.1.0.png b/downloads/espresso-cheat-sheet-2.1.0.png deleted file mode 100644 index f53b5c0e7..000000000 Binary files a/downloads/espresso-cheat-sheet-2.1.0.png and /dev/null differ diff --git a/espresso/BasicSample/app/build.gradle b/espresso/BasicSample/app/build.gradle deleted file mode 100644 index cdd6019d9..000000000 --- a/espresso/BasicSample/app/build.gradle +++ /dev/null @@ -1,33 +0,0 @@ -apply plugin: 'com.android.application' - -android { - compileSdkVersion 22 - buildToolsVersion '22.0.1' - defaultConfig { - applicationId "com.example.android.testing.espresso.BasicSample" - minSdkVersion 10 - targetSdkVersion 22 - versionCode 1 - versionName "1.0" - - testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" - } - packagingOptions { - exclude 'LICENSE.txt' - } - lintOptions { - abortOnError false - } - productFlavors { - } -} - -dependencies { - // App dependencies - compile 'com.android.support:support-annotations:22.2.0' - compile 'com.google.guava:guava:18.0' - // Testing-only dependencies - androidTestCompile 'com.android.support.test:runner:0.3' - androidTestCompile 'com.android.support.test:rules:0.3' - androidTestCompile 'com.android.support.test.espresso:espresso-core:2.2' -} diff --git a/espresso/BasicSample/build.gradle b/espresso/BasicSample/build.gradle deleted file mode 100644 index 9405f3fd1..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.2.3' - - // 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 3e950b67a..000000000 --- a/espresso/BasicSampleBundled/.classpath +++ /dev/null @@ -1,10 +0,0 @@ - - - - - - - - - - diff --git a/espresso/BasicSampleBundled/.gitignore b/espresso/BasicSampleBundled/.gitignore deleted file mode 100644 index 4a23383d6..000000000 --- a/espresso/BasicSampleBundled/.gitignore +++ /dev/null @@ -1,4 +0,0 @@ -bin -gen -.settings -project.properties 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 bc45cedcc..000000000 --- a/espresso/BasicSampleBundled/AndroidManifest.xml +++ /dev/null @@ -1,31 +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 bd450c734..000000000 Binary files a/espresso/BasicSampleBundled/libs/android-support-v4.jar and /dev/null differ diff --git a/espresso/BasicSampleBundled/libs/espresso-contrib-2.2-release-no-dep.jar b/espresso/BasicSampleBundled/libs/espresso-contrib-2.2-release-no-dep.jar deleted file mode 100644 index a2089873c..000000000 Binary files a/espresso/BasicSampleBundled/libs/espresso-contrib-2.2-release-no-dep.jar and /dev/null differ diff --git a/espresso/BasicSampleBundled/libs/espresso-core-2.2-release-no-dep.jar b/espresso/BasicSampleBundled/libs/espresso-core-2.2-release-no-dep.jar deleted file mode 100644 index 147d0e0d7..000000000 Binary files a/espresso/BasicSampleBundled/libs/espresso-core-2.2-release-no-dep.jar and /dev/null differ diff --git a/espresso/BasicSampleBundled/libs/espresso-idling-resource-2.2-release-no-dep.jar b/espresso/BasicSampleBundled/libs/espresso-idling-resource-2.2-release-no-dep.jar deleted file mode 100644 index 70b28cc2f..000000000 Binary files a/espresso/BasicSampleBundled/libs/espresso-idling-resource-2.2-release-no-dep.jar and /dev/null differ diff --git a/espresso/BasicSampleBundled/libs/espresso-intents-2.2-release-no-dep.jar b/espresso/BasicSampleBundled/libs/espresso-intents-2.2-release-no-dep.jar deleted file mode 100644 index c68c2671d..000000000 Binary files a/espresso/BasicSampleBundled/libs/espresso-intents-2.2-release-no-dep.jar and /dev/null differ diff --git a/espresso/BasicSampleBundled/libs/espresso-web-2.2-release-no-dep.jar b/espresso/BasicSampleBundled/libs/espresso-web-2.2-release-no-dep.jar deleted file mode 100644 index f6f47bca2..000000000 Binary files a/espresso/BasicSampleBundled/libs/espresso-web-2.2-release-no-dep.jar and /dev/null differ diff --git a/espresso/BasicSampleBundled/libs/exposed-instrumentation-api-publish-0.3-release-no-dep.jar b/espresso/BasicSampleBundled/libs/exposed-instrumentation-api-publish-0.3-release-no-dep.jar deleted file mode 100644 index e6a6cf96a..000000000 Binary files a/espresso/BasicSampleBundled/libs/exposed-instrumentation-api-publish-0.3-release-no-dep.jar and /dev/null differ diff --git a/espresso/BasicSampleBundled/libs/guava-18.0.jar b/espresso/BasicSampleBundled/libs/guava-18.0.jar deleted file mode 100644 index 8f89e4901..000000000 Binary files a/espresso/BasicSampleBundled/libs/guava-18.0.jar and /dev/null differ diff --git a/espresso/BasicSampleBundled/libs/hamcrest-core-1.3.jar b/espresso/BasicSampleBundled/libs/hamcrest-core-1.3.jar deleted file mode 100644 index 51f4b24ce..000000000 Binary files a/espresso/BasicSampleBundled/libs/hamcrest-core-1.3.jar and /dev/null differ diff --git a/espresso/BasicSampleBundled/libs/hamcrest-integration-1.3.jar b/espresso/BasicSampleBundled/libs/hamcrest-integration-1.3.jar deleted file mode 100644 index 6e2f02e41..000000000 Binary files a/espresso/BasicSampleBundled/libs/hamcrest-integration-1.3.jar and /dev/null differ diff --git a/espresso/BasicSampleBundled/libs/hamcrest-library-1.3.jar b/espresso/BasicSampleBundled/libs/hamcrest-library-1.3.jar deleted file mode 100644 index 197ecb331..000000000 Binary files a/espresso/BasicSampleBundled/libs/hamcrest-library-1.3.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-2.0.1.jar b/espresso/BasicSampleBundled/libs/jsr305-2.0.1.jar deleted file mode 100644 index 43807b02f..000000000 Binary files a/espresso/BasicSampleBundled/libs/jsr305-2.0.1.jar and /dev/null differ diff --git a/espresso/BasicSampleBundled/libs/junit-4.12.jar b/espresso/BasicSampleBundled/libs/junit-4.12.jar deleted file mode 100644 index 3a7fc266c..000000000 Binary files a/espresso/BasicSampleBundled/libs/junit-4.12.jar and /dev/null differ diff --git a/espresso/BasicSampleBundled/libs/rules-0.3-release-no-dep.jar b/espresso/BasicSampleBundled/libs/rules-0.3-release-no-dep.jar deleted file mode 100644 index 8d92090ac..000000000 Binary files a/espresso/BasicSampleBundled/libs/rules-0.3-release-no-dep.jar and /dev/null differ diff --git a/espresso/BasicSampleBundled/libs/runner-0.3-release-no-dep.jar b/espresso/BasicSampleBundled/libs/runner-0.3-release-no-dep.jar deleted file mode 100644 index 1083473ec..000000000 Binary files a/espresso/BasicSampleBundled/libs/runner-0.3-release-no-dep.jar and /dev/null differ diff --git a/espresso/BasicSampleBundled/libs/uiautomator-v18-2.1.1-release-no-dep.jar b/espresso/BasicSampleBundled/libs/uiautomator-v18-2.1.1-release-no-dep.jar deleted file mode 100644 index 87a7076f7..000000000 Binary files a/espresso/BasicSampleBundled/libs/uiautomator-v18-2.1.1-release-no-dep.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 00cf62bac..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-22 diff --git a/espresso/BasicSampleBundled/remove_license.sh b/espresso/BasicSampleBundled/remove_license.sh deleted file mode 100755 index ed9f43003..000000000 --- a/espresso/BasicSampleBundled/remove_license.sh +++ /dev/null @@ -1,4 +0,0 @@ -zip -d libs/hamcrest-core-1.3.jar LICENSE.txt -zip -d libs/hamcrest-library-1.3.jar LICENSE.txt -zip -d libs/hamcrest-integration-1.3.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/src/com/example/android/testing/espresso/basicsamplebundled/ShowTextActivity.java b/espresso/BasicSampleBundled/src/com/example/android/testing/espresso/basicsamplebundled/ShowTextActivity.java deleted file mode 100644 index a0d4c0bb5..000000000 --- a/espresso/BasicSampleBundled/src/com/example/android/testing/espresso/basicsamplebundled/ShowTextActivity.java +++ /dev/null @@ -1,60 +0,0 @@ -/* - * 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.espresso.basicsamplebundled; - -import android.app.Activity; -import android.content.Context; -import android.content.Intent; -import android.os.Bundle; -import android.widget.TextView; - -import com.google.common.base.Strings; - -/** - * A simple {@link Activity} that shows a message. - */ -public class ShowTextActivity extends Activity { - - // The name of the extra data sent through an {@link Intent}. - public final static String KEY_EXTRA_MESSAGE = - "com.example.android.testing.espresso.basicsample.MESSAGE"; - - @Override - protected void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - setContentView(R.layout.activity_show_text); - - // Get the message from the Intent. - Intent intent = getIntent(); - String message = Strings.nullToEmpty(intent.getStringExtra(KEY_EXTRA_MESSAGE)); - - // Show message. - ((TextView)findViewById(R.id.show_text_view)).setText(message); - } - - /** - * Creates an {@link Intent} for {@link ShowTextActivity} with the message to be displayed. - * @param context the {@link Context} where the {@link Intent} will be used - * @param message a {@link String} with text to be displayed - * @return an {@link Intent} used to start {@link ShowTextActivity} - */ - static protected Intent newStartIntent(Context context, String message) { - Intent newIntent = new Intent(context, ShowTextActivity.class); - newIntent.putExtra(KEY_EXTRA_MESSAGE, message); - return newIntent; - } -} 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 e36f77e3b..000000000 --- a/espresso/BasicSampleBundled/tests/com/example/android/testing/espresso/basicsamplebundled/tests/ChangeTextBehaviorTest.java +++ /dev/null @@ -1,94 +0,0 @@ -/* - * 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.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 org.junit.Before; -import org.junit.Rule; -import org.junit.Test; -import org.junit.runner.RunWith; - -import android.app.Activity; -import android.support.test.espresso.action.ViewActions; -import android.support.test.espresso.matcher.ViewMatchers; -import android.support.test.rule.ActivityTestRule; -import android.support.test.runner.AndroidJUnit4; -import android.test.ActivityInstrumentationTestCase2; -import android.test.suitebuilder.annotation.LargeTest; - -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}. - */ -@RunWith(AndroidJUnit4.class) -@LargeTest -public class ChangeTextBehaviorTest { - - public static final String STRING_TO_BE_TYPED = "Espresso"; - - /** - * A JUnit {@link Rule @Rule} to launch your activity under test. This is a replacement - * for {@link ActivityInstrumentationTestCase2}. - *

- * Rules are interceptors which are executed for each test method and will run before - * any of your setup code in the {@link Before @Before} method. - *

- * {@link ActivityTestRule} will create and launch of the activity for you and also expose - * the activity under test. To get a reference to the activity you can use - * the {@link ActivityTestRule#getActivity()} method. - */ - @Rule - public ActivityTestRule mActivityRule = new ActivityTestRule( - MainActivity.class); - - @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))); - } - - @Test - public void changeText_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/BasicSampleBundled/tests/com/example/android/testing/espresso/basicsamplebundled/tests/EnableJUnit4InEclipse.java b/espresso/BasicSampleBundled/tests/com/example/android/testing/espresso/basicsamplebundled/tests/EnableJUnit4InEclipse.java deleted file mode 100644 index 68922a58b..000000000 --- a/espresso/BasicSampleBundled/tests/com/example/android/testing/espresso/basicsamplebundled/tests/EnableJUnit4InEclipse.java +++ /dev/null @@ -1,36 +0,0 @@ -/* - * 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.espresso.basicsamplebundled.tests; - -import junit.framework.TestCase; - -/** - * Unfortunately this is required by Eclipse to run JUnit4 style tests. - * - *

- * This workaround tricks Eclipse into thinking there are actual tests to run. To find out if any - * tests are available, Eclipse looks at classes which extend from {@link TestCase} or - * {@link TestSuite}. As JUnit4 tests do not extend from {@link TestCase} anymore this pre-check - * fails and Eclipse will not even attempt to start the runner. - * - *

- * Once Eclipse detects this TestCase, the AndroidJUnitRunner will be able to detect the rest of the - * tests. - */ -public class EnableJUnit4InEclipse extends TestCase { - public void testDummy() {}; -} diff --git a/espresso/CustomMatcherSample/app/build.gradle b/espresso/CustomMatcherSample/app/build.gradle deleted file mode 100644 index d5c48f9ce..000000000 --- a/espresso/CustomMatcherSample/app/build.gradle +++ /dev/null @@ -1,39 +0,0 @@ -apply plugin: 'com.android.application' - -android { - compileSdkVersion 22 - buildToolsVersion '22.0.1' - defaultConfig { - applicationId "com.example.android.testing.espresso.CustomMatcherSample" - minSdkVersion 10 - targetSdkVersion 22 - 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 - } - productFlavors { - } -} - -dependencies { - // App dependencies - compile 'com.android.support:support-annotations:22.2.0' - compile 'com.google.guava:guava:18.0' - // Testing-only dependencies - androidTestCompile 'com.android.support.test:runner:0.3' - androidTestCompile 'com.android.support.test:rules:0.3' - androidTestCompile 'com.android.support.test.espresso:espresso-core:2.2' -} diff --git a/espresso/CustomMatcherSample/build.gradle b/espresso/CustomMatcherSample/build.gradle deleted file mode 100644 index 9405f3fd1..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.2.3' - - // 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 86ce91c14..000000000 --- a/espresso/DataAdapterSample/app/build.gradle +++ /dev/null @@ -1,30 +0,0 @@ -apply plugin: 'com.android.application' - -android { - compileSdkVersion 22 - buildToolsVersion '22.0.1' - defaultConfig { - applicationId "com.example.android.testing.espresso.DataAdapterSample" - minSdkVersion 10 - targetSdkVersion 22 - versionCode 1 - versionName "1.0" - testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" - - } - packagingOptions { - exclude 'LICENSE.txt' - } - productFlavors { - } -} - -dependencies { - // App dependencies - compile 'com.android.support:support-annotations:22.2.0' - compile 'com.google.guava:guava:18.0' - // Testing-only dependencies - androidTestCompile 'com.android.support.test:runner:0.3' - androidTestCompile 'com.android.support.test:rules:0.3' - androidTestCompile 'com.android.support.test.espresso:espresso-core:2.2' -} diff --git a/espresso/DataAdapterSample/build.gradle b/espresso/DataAdapterSample/build.gradle deleted file mode 100644 index 9405f3fd1..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.2.3' - - // 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/IntentsBasicSample/app/build.gradle b/espresso/IntentsBasicSample/app/build.gradle deleted file mode 100644 index 51410c3fc..000000000 --- a/espresso/IntentsBasicSample/app/build.gradle +++ /dev/null @@ -1,33 +0,0 @@ -apply plugin: 'com.android.application' - -android { - compileSdkVersion 22 - buildToolsVersion '22.0.1' - defaultConfig { - applicationId "com.example.android.testing.espresso.BasicSample" - minSdkVersion 10 - targetSdkVersion 22 - versionCode 1 - versionName "1.0" - - testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" - } - packagingOptions { - exclude 'LICENSE.txt' - } - lintOptions { - abortOnError false - } - productFlavors { - } -} - -dependencies { - // App dependencies - compile 'com.android.support:support-annotations:22.2.0' - // Testing-only dependencies - androidTestCompile 'com.android.support.test:runner:0.3' - androidTestCompile 'com.android.support.test:rules:0.3' - androidTestCompile 'com.android.support.test.espresso:espresso-core:2.2' - androidTestCompile 'com.android.support.test.espresso:espresso-intents:2.2' -} diff --git a/espresso/IntentsBasicSample/build.gradle b/espresso/IntentsBasicSample/build.gradle deleted file mode 100644 index 9405f3fd1..000000000 --- a/espresso/IntentsBasicSample/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.2.3' - - // NOTE: Do not place your application dependencies here; they belong - // in the individual module build.gradle files - } -} - -allprojects { - repositories { - jcenter() - } -} diff --git a/espresso/IntentsBasicSample/gradle/wrapper/gradle-wrapper.jar b/espresso/IntentsBasicSample/gradle/wrapper/gradle-wrapper.jar deleted file mode 100644 index 8c0fb64a8..000000000 Binary files a/espresso/IntentsBasicSample/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 0eb97f4d6..000000000 --- a/espresso/MultiWindowSample/app/build.gradle +++ /dev/null @@ -1,40 +0,0 @@ - -apply plugin: 'com.android.application' - -android { - compileSdkVersion 22 - buildToolsVersion '22.0.1' - defaultConfig { - applicationId "com.example.android.testing.espresso.MultiWindowSample" - minSdkVersion 10 - targetSdkVersion 22 - 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 - } - productFlavors { - } -} - -dependencies { - // App dependencies - compile 'com.android.support:support-annotations:22.2.0' - compile 'com.google.guava:guava:18.0' - // Testing-only dependencies - androidTestCompile 'com.android.support.test:runner:0.3' - androidTestCompile 'com.android.support.test:rules:0.3' - androidTestCompile 'com.android.support.test.espresso:espresso-core:2.2' -} diff --git a/espresso/MultiWindowSample/build.gradle b/espresso/MultiWindowSample/build.gradle deleted file mode 100644 index 9405f3fd1..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.2.3' - - // 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.properties b/espresso/MultiWindowSample/gradle.properties deleted file mode 100644 index 1d3591c8a..000000000 --- a/espresso/MultiWindowSample/gradle.properties +++ /dev/null @@ -1,18 +0,0 @@ -# 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. -# Default value: -Xmx10248m -XX:MaxPermSize=256m -# org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8 - -# 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 \ No newline at end of file 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/espresso/MultiWindowSample/gradle/wrapper/gradle-wrapper.properties b/espresso/MultiWindowSample/gradle/wrapper/gradle-wrapper.properties deleted file mode 100644 index ed7059864..000000000 --- a/espresso/MultiWindowSample/gradle/wrapper/gradle-wrapper.properties +++ /dev/null @@ -1,6 +0,0 @@ -#Mon Nov 17 11:45:05 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/MultiWindowSample/gradlew b/espresso/MultiWindowSample/gradlew deleted file mode 100755 index 91a7e269e..000000000 --- a/espresso/MultiWindowSample/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/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/gradlew.bat b/gradlew.bat deleted file mode 100644 index aec99730b..000000000 --- a/gradlew.bat +++ /dev/null @@ -1,90 +0,0 @@ -@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 - -@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= - -set DIRNAME=%~dp0 -if "%DIRNAME%" == "" set DIRNAME=. -set APP_BASE_NAME=%~n0 -set APP_HOME=%DIRNAME% - -@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 Windowz variants - -if not "%OS%" == "Windows_NT" goto win9xME_args -if "%@eval[2+2]" == "4" goto 4NT_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=%* -goto execute - -:4NT_args -@rem Get arguments from the 4NT Shell from JP Software -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 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/integrationtesting/ServiceTestRuleSample/README.md b/integration/ServiceTestRuleSample/README.md similarity index 100% rename from integrationtesting/ServiceTestRuleSample/README.md rename to integration/ServiceTestRuleSample/README.md 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/integrationtesting/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 similarity index 88% rename from integrationtesting/ServiceTestRuleSample/app/src/androidTest/java/com.example.android.testing.ServiceTestRuleSample/LocalServiceTest.java rename to integration/ServiceTestRuleSample/app/src/androidTest/java/com/example/android/testing/ServiceTestRuleSample/LocalServiceTest.java index 6009201d3..d81362862 100644 --- a/integrationtesting/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 @@ -18,14 +18,17 @@ import android.content.Intent; import android.os.IBinder; -import android.support.test.InstrumentationRegistry; -import android.support.test.rule.ServiceTestRule; +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; @@ -47,6 +50,8 @@ * 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(); @@ -55,7 +60,7 @@ public class LocalServiceTest { public void testWithBoundService() throws TimeoutException { // Create the service Intent. Intent serviceIntent = - new Intent(InstrumentationRegistry.getTargetContext(), LocalService.class); + new Intent(getApplicationContext(), LocalService.class); // Data can be passed to the service via the Intent. serviceIntent.putExtra(LocalService.SEED_KEY, 42L); diff --git a/integrationtesting/ServiceTestRuleSample/app/src/main/AndroidManifest.xml b/integration/ServiceTestRuleSample/app/src/main/AndroidManifest.xml similarity index 86% rename from integrationtesting/ServiceTestRuleSample/app/src/main/AndroidManifest.xml rename to integration/ServiceTestRuleSample/app/src/main/AndroidManifest.xml index d881131aa..5dc076f8c 100644 --- a/integrationtesting/ServiceTestRuleSample/app/src/main/AndroidManifest.xml +++ b/integration/ServiceTestRuleSample/app/src/main/AndroidManifest.xml @@ -16,8 +16,7 @@ --> - + '} + case $link in #( + /*) app_path=$link ;; #( + *) app_path=$APP_HOME$link ;; + esac +done + +APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit + +APP_NAME="Gradle" +APP_BASE_NAME=${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='"-Xmx64m" "-Xms64m"' + +# Use the maximum available, or set MAX_FD != -1 to use that value. +MAX_FD=maximum + +warn () { + echo "$*" +} >&2 + +die () { + echo + echo "$*" + echo + exit 1 +} >&2 + +# 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 ;; #( + MSYS* | 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" && ! "$darwin" && ! "$nonstop" ; then + case $MAX_FD in #( + max*) + MAX_FD=$( ulimit -H -n ) || + warn "Could not query maximum file descriptor limit" + esac + case $MAX_FD in #( + '' | soft) :;; #( + *) + ulimit -n "$MAX_FD" || + warn "Could not set maximum file descriptor limit to $MAX_FD" + esac +fi + +# Collect all arguments for the java command, stacking in reverse order: +# * args from the command line +# * the main class name +# * -classpath +# * -D...appname settings +# * --module-path (only if needed) +# * DEFAULT_JVM_OPTS, JAVA_OPTS, and GRADLE_OPTS environment variables. + +# For Cygwin or MSYS, switch paths to Windows format before running java +if "$cygwin" || "$msys" ; then + APP_HOME=$( cygpath --path --mixed "$APP_HOME" ) + CLASSPATH=$( cygpath --path --mixed "$CLASSPATH" ) + + JAVACMD=$( cygpath --unix "$JAVACMD" ) + + # Now convert the arguments - kludge to limit ourselves to /bin/sh + for arg do + if + case $arg in #( + -*) false ;; # don't mess with options #( + /?*) t=${arg#/} t=/${t%%/*} # looks like a POSIX filepath + [ -e "$t" ] ;; #( + *) false ;; + esac + then + arg=$( cygpath --path --ignore --mixed "$arg" ) + fi + # Roll the args list around exactly as many times as the number of + # args, so each arg winds up back in the position where it started, but + # possibly modified. + # + # NB: a `for` loop captures its iteration list before it begins, so + # changing the positional parameters here affects neither the number of + # iterations, nor the values presented in `arg`. + shift # remove old arg + set -- "$@" "$arg" # push replacement arg + done +fi + +# Collect all arguments for the java command; +# * $DEFAULT_JVM_OPTS, $JAVA_OPTS, and $GRADLE_OPTS can contain fragments of +# shell script including quotes and variable substitutions, so put them in +# double quotes to make sure that they get re-expanded; and +# * put everything else in single quotes, so that it's not re-expanded. + +set -- \ + "-Dorg.gradle.appname=$APP_BASE_NAME" \ + -classpath "$CLASSPATH" \ + org.gradle.wrapper.GradleWrapperMain \ + "$@" + +# Use "xargs" to parse quoted args. +# +# With -n1 it outputs one arg per line, with the quotes and backslashes removed. +# +# In Bash we could simply go: +# +# readarray ARGS < <( xargs -n1 <<<"$var" ) && +# set -- "${ARGS[@]}" "$@" +# +# but POSIX shell has neither arrays nor command substitution, so instead we +# post-process each arg (as a line of input to sed) to backslash-escape any +# character that might be a shell metacharacter, then use eval to reverse +# that process (while maintaining the separation between arguments), and wrap +# the whole thing up as a single "set" statement. +# +# This will of course break if any of these variables contains a newline or +# an unmatched quote. +# + +eval "set -- $( + printf '%s\n' "$DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS" | + xargs -n1 | + sed ' s~[^-[:alnum:]+,./:=@_]~\\&~g; ' | + tr '\n' ' ' + )" '"$@"' + +exec "$JAVACMD" "$@" diff --git a/espresso/IntentsBasicSample/gradlew.bat b/integration/ServiceTestRuleSample/gradlew.bat similarity index 64% rename from espresso/IntentsBasicSample/gradlew.bat rename to integration/ServiceTestRuleSample/gradlew.bat index aec99730b..ac1b06f93 100644 --- a/espresso/IntentsBasicSample/gradlew.bat +++ b/integration/ServiceTestRuleSample/gradlew.bat @@ -1,3 +1,19 @@ +@rem +@rem Copyright 2015 the original author or authors. +@rem +@rem Licensed under the Apache License, Version 2.0 (the "License"); +@rem you may not use this file except in compliance with the License. +@rem You may obtain a copy of the License at +@rem +@rem https://www.apache.org/licenses/LICENSE-2.0 +@rem +@rem Unless required by applicable law or agreed to in writing, software +@rem distributed under the License is distributed on an "AS IS" BASIS, +@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +@rem See the License for the specific language governing permissions and +@rem limitations under the License. +@rem + @if "%DEBUG%" == "" @echo off @rem ########################################################################## @rem @@ -8,20 +24,23 @@ @rem Set local scope for the variables with windows NT shell if "%OS%"=="Windows_NT" setlocal -@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= - set DIRNAME=%~dp0 if "%DIRNAME%" == "" set DIRNAME=. set APP_BASE_NAME=%~n0 set APP_HOME=%DIRNAME% +@rem Resolve any "." and ".." in APP_HOME to make it shorter. +for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi + +@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="-Xmx64m" "-Xms64m" + @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 +if "%ERRORLEVEL%" == "0" goto execute echo. echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. @@ -35,7 +54,7 @@ goto fail set JAVA_HOME=%JAVA_HOME:"=% set JAVA_EXE=%JAVA_HOME%/bin/java.exe -if exist "%JAVA_EXE%" goto init +if exist "%JAVA_EXE%" goto execute echo. echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% @@ -45,34 +64,14 @@ echo location of your Java installation. goto fail -:init -@rem Get command-line arguments, handling Windowz variants - -if not "%OS%" == "Windows_NT" goto win9xME_args -if "%@eval[2+2]" == "4" goto 4NT_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=%* -goto execute - -:4NT_args -@rem Get arguments from the 4NT Shell from JP Software -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% +"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %* :end @rem End local scope for the variables with windows NT shell diff --git a/espresso/BasicSample/settings.gradle b/integration/ServiceTestRuleSample/settings.gradle similarity index 100% rename from espresso/BasicSample/settings.gradle rename to integration/ServiceTestRuleSample/settings.gradle diff --git a/integrationtesting/ServiceTestRuleSample/app/build.gradle b/integrationtesting/ServiceTestRuleSample/app/build.gradle deleted file mode 100644 index d51214d25..000000000 --- a/integrationtesting/ServiceTestRuleSample/app/build.gradle +++ /dev/null @@ -1,29 +0,0 @@ -apply plugin: 'com.android.application' - -android { - compileSdkVersion 22 - buildToolsVersion '22.0.1' - defaultConfig { - applicationId "com.example.android.testing.integrationtesting.ServiceTestRuleSample" - minSdkVersion 10 - targetSdkVersion 22 - versionCode 1 - versionName "1.0" - - testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" - } - packagingOptions { - exclude 'LICENSE.txt' - } - lintOptions { - abortOnError false - } - productFlavors { - } -} - -dependencies { - // Testing-only dependencies - androidTestCompile 'com.android.support.test:runner:0.3' - androidTestCompile 'com.android.support.test:rules:0.3' -} diff --git a/integrationtesting/ServiceTestRuleSample/build.gradle b/integrationtesting/ServiceTestRuleSample/build.gradle deleted file mode 100644 index 9405f3fd1..000000000 --- a/integrationtesting/ServiceTestRuleSample/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.2.3' - - // NOTE: Do not place your application dependencies here; they belong - // in the individual module build.gradle files - } -} - -allprojects { - repositories { - jcenter() - } -} diff --git a/integrationtesting/ServiceTestRuleSample/gradle.properties b/integrationtesting/ServiceTestRuleSample/gradle.properties deleted file mode 100644 index 1d3591c8a..000000000 --- a/integrationtesting/ServiceTestRuleSample/gradle.properties +++ /dev/null @@ -1,18 +0,0 @@ -# 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. -# Default value: -Xmx10248m -XX:MaxPermSize=256m -# org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8 - -# 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 \ No newline at end of file diff --git a/integrationtesting/ServiceTestRuleSample/gradle/wrapper/gradle-wrapper.jar b/integrationtesting/ServiceTestRuleSample/gradle/wrapper/gradle-wrapper.jar deleted file mode 100644 index 8c0fb64a8..000000000 Binary files a/integrationtesting/ServiceTestRuleSample/gradle/wrapper/gradle-wrapper.jar and /dev/null differ diff --git a/integrationtesting/ServiceTestRuleSample/gradle/wrapper/gradle-wrapper.properties b/integrationtesting/ServiceTestRuleSample/gradle/wrapper/gradle-wrapper.properties deleted file mode 100644 index 0ed71dbdb..000000000 --- a/integrationtesting/ServiceTestRuleSample/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/integrationtesting/ServiceTestRuleSample/gradlew b/integrationtesting/ServiceTestRuleSample/gradlew deleted file mode 100755 index 91a7e269e..000000000 --- a/integrationtesting/ServiceTestRuleSample/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/integrationtesting/ServiceTestRuleSample/gradlew.bat b/integrationtesting/ServiceTestRuleSample/gradlew.bat deleted file mode 100644 index aec99730b..000000000 --- a/integrationtesting/ServiceTestRuleSample/gradlew.bat +++ /dev/null @@ -1,90 +0,0 @@ -@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 - -@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= - -set DIRNAME=%~dp0 -if "%DIRNAME%" == "" set DIRNAME=. -set APP_BASE_NAME=%~n0 -set APP_HOME=%DIRNAME% - -@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 Windowz variants - -if not "%OS%" == "Windows_NT" goto win9xME_args -if "%@eval[2+2]" == "4" goto 4NT_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=%* -goto execute - -:4NT_args -@rem Get arguments from the 4NT Shell from JP Software -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 diff --git a/projects.conf b/projects.conf new file mode 100644 index 000000000..f9b14cdb2 --- /dev/null +++ b/projects.conf @@ -0,0 +1,19 @@ +integration/ServiceTestRuleSample +runner/AndroidJunitRunnerSample +runner/AndroidTestOrchestratorSample +ui/espresso/AccessibilitySample +ui/espresso/BasicSample +ui/espresso/CustomMatcherSample +ui/espresso/DataAdapterSample +ui/espresso/EspressoDeviceSample +ui/espresso/FragmentScenarioSample +ui/espresso/IdlingResourceSample +ui/espresso/IntentsAdvancedSample +ui/espresso/IntentsBasicSample +ui/espresso/MultiWindowSample +ui/espresso/MultiProcessSample +ui/espresso/RecyclerViewSample +ui/espresso/ScreenshotSample +ui/espresso/WebBasicSample +ui/uiautomator/BasicSample +unit/BasicNativeAndroidTest diff --git a/renovate.json b/renovate.json new file mode 100644 index 000000000..abf4b0566 --- /dev/null +++ b/renovate.json @@ -0,0 +1,6 @@ +{ + "$schema": "https://docs.renovatebot.com/renovate-schema.json", + "extends": [ + "local>android/.github:renovate-config" + ] +} diff --git a/testrunner/AndroidJunitRunnerSample/.gitignore b/runner/AndroidJunitRunnerSample/.gitignore similarity index 100% rename from testrunner/AndroidJunitRunnerSample/.gitignore rename to runner/AndroidJunitRunnerSample/.gitignore diff --git a/testrunner/AndroidJunitRunnerSample/README.md b/runner/AndroidJunitRunnerSample/README.md similarity index 82% rename from testrunner/AndroidJunitRunnerSample/README.md rename to runner/AndroidJunitRunnerSample/README.md index 96d4677bd..e55555668 100644 --- a/testrunner/AndroidJunitRunnerSample/README.md +++ b/runner/AndroidJunitRunnerSample/README.md @@ -18,15 +18,16 @@ This project uses the Gradle build system. You don't need an IDE to build and ex 1. Check out the relevant code: * The application under test is located in `src/main/java` * Tests are in `src/androidTest/java` -1. Create the test configuration with a custom runner: `android.support.test.runner.AndroidJUnitRunner` +1. Create the test configuration with a custom runner: `androidx.test.runner.AndroidJUnitRunner` * Open *Run* menu | *Edit Configurations* * Add a new *Android Tests* configuration * Choose a module * Choose which tests to run. Click on Test: class and select one of the TestSuites (AndroidTestSuite, UnitTestSuite, InstrumentationTestSuite) - * Add a *Specific instrumentation runner*: `android.support.test.runner.AndroidJUnitRunner` + * Add a *Specific instrumentation runner*: `androidx.test.runner.AndroidJUnitRunner` 1. Connect a device or start an emulator - * [https://code.google.com/p/android-test-kit/wiki/DisablingAnimations Turn animations off]. + * Turn animations off. + (On your device, under Settings->Developer options disable the following 3 settings: "Window animation scale", "Transition animation scale" and "Animator duration scale") 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/runner/AndroidJunitRunnerSample/app/build.gradle b/runner/AndroidJunitRunnerSample/app/build.gradle new file mode 100644 index 000000000..072763155 --- /dev/null +++ b/runner/AndroidJunitRunnerSample/app/build.gradle @@ -0,0 +1,58 @@ +apply plugin: "com.android.application" + + +android { + compileSdk 34 + defaultConfig { + applicationId "com.example.android.testing.androidjunitrunnersample" + minSdkVersion 21 + targetSdkVersion 34 + versionCode 1 + versionName "1.0" + + testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" + } + buildTypes { + release { + minifyEnabled false + proguardFiles getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro" + } + } + 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" + } + } + } + } + useLibrary "android.test.runner" + + useLibrary "android.test.base" + useLibrary "android.test.mock" + namespace "com.example.android.testing.androidjunitrunnersample" + +} + +dependencies { + // App's dependencies, including test + 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; + + // https://truth.dev/ + androidTestImplementation "com.google.truth:truth:" + rootProject.truthVersion; +} diff --git a/runner/AndroidJunitRunnerSample/app/src/androidTest/java/com/example/android/testing/androidjunitrunnersample/CalculatorAddParameterizedTest.java b/runner/AndroidJunitRunnerSample/app/src/androidTest/java/com/example/android/testing/androidjunitrunnersample/CalculatorAddParameterizedTest.java new file mode 100644 index 000000000..8b2634103 --- /dev/null +++ b/runner/AndroidJunitRunnerSample/app/src/androidTest/java/com/example/android/testing/androidjunitrunnersample/CalculatorAddParameterizedTest.java @@ -0,0 +1,91 @@ +/* + * 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.androidjunitrunnersample; + +import static com.google.common.truth.Truth.assertThat; +import static org.junit.runners.Parameterized.Parameters; + +import androidx.test.filters.SmallTest; + +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.Parameterized; + +import java.util.Arrays; + + +/** + * JUnit4 tests for the calculator's add logic. + * + *

This test uses Junit4s Parameterized tests features which uses annotations to pass + * parameters into a unit test. The way this works is that you have to use the {@link Parameterized} + * runner to run your tests. + *

+ */ +@RunWith(Parameterized.class) +@SmallTest +public class CalculatorAddParameterizedTest { + + /** + * @return {@link Iterable} that contains the values that should be passed to the constructor. + * In this example we are going to use three parameters: operand one, operand two and the + * expected result. + */ + @Parameters + public static Iterable data() { + return Arrays.asList(new Object[][]{ + {0, 0, 0}, + {0, -1, -1}, + {2, 2, 4}, + {8, 8, 16}, + {16, 16, 32}, + {32, 0, 32}, + {64, 64, 128}}); + } + + private final double mOperandOne; + private final double mOperandTwo; + private final double mExpectedResult; + + private Calculator mCalculator; + + /** + * Constructor that takes in the values specified in + * {@link CalculatorAddParameterizedTest#data()}. The values need to be saved to fields in order + * to reuse them in your tests. + */ + public CalculatorAddParameterizedTest(double operandOne, double operandTwo, + double expectedResult) { + + mOperandOne = operandOne; + mOperandTwo = operandTwo; + mExpectedResult = expectedResult; + } + + @Before + public void setUp() { + mCalculator = new Calculator(); + } + + @Test + public void testAdd_TwoNumbers() { + double resultAdd = mCalculator.add(mOperandOne, mOperandTwo); + assertThat(resultAdd).isEqualTo(mExpectedResult); + } + +} diff --git a/testrunner/AndroidJunitRunnerSample/app/src/androidTest/java/com/example/android/testing/androidjunitrunnersample/CalculatorInstrumentationTest.java b/runner/AndroidJunitRunnerSample/app/src/androidTest/java/com/example/android/testing/androidjunitrunnersample/CalculatorInstrumentationTest.java similarity index 64% rename from testrunner/AndroidJunitRunnerSample/app/src/androidTest/java/com/example/android/testing/androidjunitrunnersample/CalculatorInstrumentationTest.java rename to runner/AndroidJunitRunnerSample/app/src/androidTest/java/com/example/android/testing/androidjunitrunnersample/CalculatorInstrumentationTest.java index 369fb1602..8cdde1d39 100644 --- a/testrunner/AndroidJunitRunnerSample/app/src/androidTest/java/com/example/android/testing/androidjunitrunnersample/CalculatorInstrumentationTest.java +++ b/runner/AndroidJunitRunnerSample/app/src/androidTest/java/com/example/android/testing/androidjunitrunnersample/CalculatorInstrumentationTest.java @@ -19,24 +19,23 @@ import junit.framework.TestSuite; import org.junit.Before; -import org.junit.Rule; import org.junit.Test; import org.junit.internal.builders.AllDefaultPossibilitiesBuilder; import org.junit.runner.RunWith; -import android.support.test.rule.ActivityTestRule; -import android.support.test.runner.AndroidJUnit4; -import android.support.test.runner.AndroidJUnitRunner; -import android.test.ActivityInstrumentationTestCase2; -import android.test.suitebuilder.annotation.LargeTest; +import androidx.test.core.app.ActivityScenario; +import androidx.test.ext.junit.runners.AndroidJUnit4; +import androidx.test.filters.LargeTest; +import androidx.test.runner.AndroidJUnitRunner; -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 static androidx.test.core.app.ApplicationProvider.getApplicationContext; +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; /** * JUnit4 Ui Tests for {@link CalculatorActivity} using the {@link AndroidJUnitRunner}. @@ -52,23 +51,16 @@ public class CalculatorInstrumentationTest { /** - * A JUnit {@link Rule @Rule} to launch your activity under test. This is a replacement - * for {@link ActivityInstrumentationTestCase2}. - *

- * Rules are interceptors which are executed for each test method and will run before - * any of your setup code in the {@link Before @Before} method. - *

- * {@link ActivityTestRule} will create and launch of the activity for you and also expose - * the activity under test. To get a reference to the activity you can use - * the {@link ActivityTestRule#getActivity()} method. + * Use {@link ActivityScenario} to create and launch of the activity. */ - @Rule - public ActivityTestRule mActivityRule = new ActivityTestRule<>( - CalculatorActivity.class); + @Before + public void launchActivity() { + ActivityScenario.launch(CalculatorActivity.class); + } @Test public void noOperandShowsComputationError() { - final String expectedResult = mActivityRule.getActivity().getString(R.string.computationError); + final String expectedResult = getApplicationContext().getString(R.string.computationError); onView(withId(R.id.operation_add_btn)).perform(click()); onView(withId(R.id.operation_result_text_view)).check(matches(withText(expectedResult))); } @@ -90,8 +82,7 @@ public void typeOperandsAndPerformDivOperation() { @Test public void divZeroForOperandTwoShowsError() { - final String expectedResult = mActivityRule.getActivity().getString( - R.string.computationError); + final String expectedResult = getApplicationContext().getString(R.string.computationError); performOperation(R.id.operation_div_btn, "128.0", "0.0", expectedResult); } diff --git a/testrunner/AndroidJunitRunnerSample/app/src/androidTest/java/com/example/android/testing/androidjunitrunnersample/CalculatorTest.java b/runner/AndroidJunitRunnerSample/app/src/androidTest/java/com/example/android/testing/androidjunitrunnersample/CalculatorTest.java similarity index 77% rename from testrunner/AndroidJunitRunnerSample/app/src/androidTest/java/com/example/android/testing/androidjunitrunnersample/CalculatorTest.java rename to runner/AndroidJunitRunnerSample/app/src/androidTest/java/com/example/android/testing/androidjunitrunnersample/CalculatorTest.java index 8c6eff5b7..f6797a081 100644 --- a/testrunner/AndroidJunitRunnerSample/app/src/androidTest/java/com/example/android/testing/androidjunitrunnersample/CalculatorTest.java +++ b/runner/AndroidJunitRunnerSample/app/src/androidTest/java/com/example/android/testing/androidjunitrunnersample/CalculatorTest.java @@ -16,16 +16,15 @@ package com.example.android.testing.androidjunitrunnersample; +import static com.google.common.truth.Truth.assertThat; + +import androidx.test.ext.junit.runners.AndroidJUnit4; +import androidx.test.filters.SmallTest; + import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; -import android.support.test.runner.AndroidJUnit4; -import android.test.suitebuilder.annotation.SmallTest; - -import static org.hamcrest.CoreMatchers.equalTo; -import static org.hamcrest.CoreMatchers.is; -import static org.junit.Assert.assertThat; /** @@ -45,25 +44,25 @@ public void setUp() { @Test public void addTwoNumbers() { double resultAdd = mCalculator.add(1d, 1d); - assertThat(resultAdd, is(equalTo(2d))); + assertThat(resultAdd).isEqualTo(2d); } @Test public void subTwoNumbers() { double resultSub = mCalculator.sub(1d, 1d); - assertThat(resultSub, is(equalTo(0d))); + assertThat(resultSub).isEqualTo(0d); } @Test public void subWorksWithNegativeResult() { double resultSub = mCalculator.sub(1d, 17d); - assertThat(resultSub, is(equalTo(-16d))); + assertThat(resultSub).isEqualTo(-16d); } @Test public void divTwoNumbers() { double resultDiv = mCalculator.div(32d,2d); - assertThat(resultDiv, is(equalTo(16d))); + assertThat(resultDiv).isEqualTo(16d); } @Test(expected = IllegalArgumentException.class) @@ -74,7 +73,7 @@ public void divDivideByZeroThrows() { @Test public void mulTwoNumbers() { double resultMul = mCalculator.mul(32d, 2d); - assertThat(resultMul, is(equalTo(64d))); + assertThat(resultMul).isEqualTo(64d); } } \ No newline at end of file diff --git a/testrunner/AndroidJunitRunnerSample/app/src/androidTest/java/com/example/android/testing/androidjunitrunnersample/HintMatcher.java b/runner/AndroidJunitRunnerSample/app/src/androidTest/java/com/example/android/testing/androidjunitrunnersample/HintMatcher.java similarity index 96% rename from testrunner/AndroidJunitRunnerSample/app/src/androidTest/java/com/example/android/testing/androidjunitrunnersample/HintMatcher.java rename to runner/AndroidJunitRunnerSample/app/src/androidTest/java/com/example/android/testing/androidjunitrunnersample/HintMatcher.java index c8310ed35..ea7481845 100644 --- a/testrunner/AndroidJunitRunnerSample/app/src/androidTest/java/com/example/android/testing/androidjunitrunnersample/HintMatcher.java +++ b/runner/AndroidJunitRunnerSample/app/src/androidTest/java/com/example/android/testing/androidjunitrunnersample/HintMatcher.java @@ -16,7 +16,7 @@ package com.example.android.testing.androidjunitrunnersample; -import android.support.test.espresso.matcher.BoundedMatcher; +import androidx.test.espresso.matcher.BoundedMatcher; import org.hamcrest.Description; import org.hamcrest.Matcher; diff --git a/testrunner/AndroidJunitRunnerSample/app/src/androidTest/java/com/example/android/testing/androidjunitrunnersample/OperationHintInstrumentationTest.java b/runner/AndroidJunitRunnerSample/app/src/androidTest/java/com/example/android/testing/androidjunitrunnersample/OperationHintInstrumentationTest.java similarity index 87% rename from testrunner/AndroidJunitRunnerSample/app/src/androidTest/java/com/example/android/testing/androidjunitrunnersample/OperationHintInstrumentationTest.java rename to runner/AndroidJunitRunnerSample/app/src/androidTest/java/com/example/android/testing/androidjunitrunnersample/OperationHintInstrumentationTest.java index ee2753057..54898a02c 100644 --- a/testrunner/AndroidJunitRunnerSample/app/src/androidTest/java/com/example/android/testing/androidjunitrunnersample/OperationHintInstrumentationTest.java +++ b/runner/AndroidJunitRunnerSample/app/src/androidTest/java/com/example/android/testing/androidjunitrunnersample/OperationHintInstrumentationTest.java @@ -18,17 +18,16 @@ import junit.framework.TestSuite; -import org.junit.Test; import org.junit.internal.builders.AllDefaultPossibilitiesBuilder; -import android.support.test.runner.AndroidJUnitRunner; +import androidx.test.filters.LargeTest; +import androidx.test.runner.AndroidJUnitRunner; import android.test.ActivityInstrumentationTestCase2; -import android.test.suitebuilder.annotation.LargeTest; import static com.example.android.testing.androidjunitrunnersample.HintMatcher.withHint; -import static android.support.test.espresso.Espresso.onView; -import static android.support.test.espresso.assertion.ViewAssertions.matches; -import static android.support.test.espresso.matcher.ViewMatchers.withId; +import static androidx.test.espresso.Espresso.onView; +import static androidx.test.espresso.assertion.ViewAssertions.matches; +import static androidx.test.espresso.matcher.ViewMatchers.withId; import static org.hamcrest.CoreMatchers.notNullValue; import static org.junit.Assert.assertThat; diff --git a/testrunner/AndroidJunitRunnerSample/app/src/androidTest/java/com/example/android/testing/androidjunitrunnersample/OperationHintLegacyInstrumentationTest.java b/runner/AndroidJunitRunnerSample/app/src/androidTest/java/com/example/android/testing/androidjunitrunnersample/OperationHintLegacyInstrumentationTest.java similarity index 89% rename from testrunner/AndroidJunitRunnerSample/app/src/androidTest/java/com/example/android/testing/androidjunitrunnersample/OperationHintLegacyInstrumentationTest.java rename to runner/AndroidJunitRunnerSample/app/src/androidTest/java/com/example/android/testing/androidjunitrunnersample/OperationHintLegacyInstrumentationTest.java index 6015fb69f..a6226abdb 100644 --- a/testrunner/AndroidJunitRunnerSample/app/src/androidTest/java/com/example/android/testing/androidjunitrunnersample/OperationHintLegacyInstrumentationTest.java +++ b/runner/AndroidJunitRunnerSample/app/src/androidTest/java/com/example/android/testing/androidjunitrunnersample/OperationHintLegacyInstrumentationTest.java @@ -20,13 +20,13 @@ import org.junit.internal.builders.AllDefaultPossibilitiesBuilder; -import android.support.test.runner.AndroidJUnitRunner; +import androidx.test.filters.LargeTest; +import androidx.test.runner.AndroidJUnitRunner; import android.test.ActivityInstrumentationTestCase2; -import android.test.suitebuilder.annotation.LargeTest; -import static android.support.test.espresso.Espresso.onView; -import static android.support.test.espresso.assertion.ViewAssertions.matches; -import static android.support.test.espresso.matcher.ViewMatchers.withId; +import static androidx.test.espresso.Espresso.onView; +import static androidx.test.espresso.assertion.ViewAssertions.matches; +import static androidx.test.espresso.matcher.ViewMatchers.withId; import static com.example.android.testing.androidjunitrunnersample.HintMatcher.withHint; import static org.hamcrest.CoreMatchers.notNullValue; import static org.junit.Assert.assertThat; diff --git a/testrunner/AndroidJunitRunnerSample/app/src/androidTest/java/com/example/android/testing/androidjunitrunnersample/suite/AndroidTestSuite.java b/runner/AndroidJunitRunnerSample/app/src/androidTest/java/com/example/android/testing/androidjunitrunnersample/suite/AndroidTestSuite.java similarity index 100% rename from testrunner/AndroidJunitRunnerSample/app/src/androidTest/java/com/example/android/testing/androidjunitrunnersample/suite/AndroidTestSuite.java rename to runner/AndroidJunitRunnerSample/app/src/androidTest/java/com/example/android/testing/androidjunitrunnersample/suite/AndroidTestSuite.java diff --git a/testrunner/AndroidJunitRunnerSample/app/src/androidTest/java/com/example/android/testing/androidjunitrunnersample/suite/InstrumentationTestSuite.java b/runner/AndroidJunitRunnerSample/app/src/androidTest/java/com/example/android/testing/androidjunitrunnersample/suite/InstrumentationTestSuite.java similarity index 100% rename from testrunner/AndroidJunitRunnerSample/app/src/androidTest/java/com/example/android/testing/androidjunitrunnersample/suite/InstrumentationTestSuite.java rename to runner/AndroidJunitRunnerSample/app/src/androidTest/java/com/example/android/testing/androidjunitrunnersample/suite/InstrumentationTestSuite.java diff --git a/testrunner/AndroidJunitRunnerSample/app/src/androidTest/java/com/example/android/testing/androidjunitrunnersample/suite/UnitTestSuite.java b/runner/AndroidJunitRunnerSample/app/src/androidTest/java/com/example/android/testing/androidjunitrunnersample/suite/UnitTestSuite.java similarity index 100% rename from testrunner/AndroidJunitRunnerSample/app/src/androidTest/java/com/example/android/testing/androidjunitrunnersample/suite/UnitTestSuite.java rename to runner/AndroidJunitRunnerSample/app/src/androidTest/java/com/example/android/testing/androidjunitrunnersample/suite/UnitTestSuite.java diff --git a/testrunner/AndroidJunitRunnerSample/app/src/main/AndroidManifest.xml b/runner/AndroidJunitRunnerSample/app/src/main/AndroidManifest.xml similarity index 90% rename from testrunner/AndroidJunitRunnerSample/app/src/main/AndroidManifest.xml rename to runner/AndroidJunitRunnerSample/app/src/main/AndroidManifest.xml index ed5bc18ae..bdbe7358c 100644 --- a/testrunner/AndroidJunitRunnerSample/app/src/main/AndroidManifest.xml +++ b/runner/AndroidJunitRunnerSample/app/src/main/AndroidManifest.xml @@ -15,8 +15,7 @@ limitations under the License. --> - + + android:label="@string/app_name" + android:exported="true"> diff --git a/testrunner/AndroidJunitRunnerSample/app/src/main/java/com/example/android/testing/androidjunitrunnersample/Calculator.java b/runner/AndroidJunitRunnerSample/app/src/main/java/com/example/android/testing/androidjunitrunnersample/Calculator.java similarity index 99% rename from testrunner/AndroidJunitRunnerSample/app/src/main/java/com/example/android/testing/androidjunitrunnersample/Calculator.java rename to runner/AndroidJunitRunnerSample/app/src/main/java/com/example/android/testing/androidjunitrunnersample/Calculator.java index b0ded529e..8b824e1f7 100644 --- a/testrunner/AndroidJunitRunnerSample/app/src/main/java/com/example/android/testing/androidjunitrunnersample/Calculator.java +++ b/runner/AndroidJunitRunnerSample/app/src/main/java/com/example/android/testing/androidjunitrunnersample/Calculator.java @@ -51,6 +51,7 @@ public double div(double firstOperand, double secondOperand) { * Multiply operation */ public double mul(double firstOperand, double secondOperand) { + return firstOperand * secondOperand; } } diff --git a/testrunner/AndroidJunitRunnerSample/app/src/main/java/com/example/android/testing/androidjunitrunnersample/CalculatorActivity.java b/runner/AndroidJunitRunnerSample/app/src/main/java/com/example/android/testing/androidjunitrunnersample/CalculatorActivity.java similarity index 100% rename from testrunner/AndroidJunitRunnerSample/app/src/main/java/com/example/android/testing/androidjunitrunnersample/CalculatorActivity.java rename to runner/AndroidJunitRunnerSample/app/src/main/java/com/example/android/testing/androidjunitrunnersample/CalculatorActivity.java diff --git a/testrunner/AndroidJunitRunnerSample/app/src/main/res/drawable-hdpi/ic_launcher.png b/runner/AndroidJunitRunnerSample/app/src/main/res/drawable-hdpi/ic_launcher.png similarity index 100% rename from testrunner/AndroidJunitRunnerSample/app/src/main/res/drawable-hdpi/ic_launcher.png rename to runner/AndroidJunitRunnerSample/app/src/main/res/drawable-hdpi/ic_launcher.png diff --git a/testrunner/AndroidJunitRunnerSample/app/src/main/res/drawable-mdpi/ic_launcher.png b/runner/AndroidJunitRunnerSample/app/src/main/res/drawable-mdpi/ic_launcher.png similarity index 100% rename from testrunner/AndroidJunitRunnerSample/app/src/main/res/drawable-mdpi/ic_launcher.png rename to runner/AndroidJunitRunnerSample/app/src/main/res/drawable-mdpi/ic_launcher.png diff --git a/testrunner/AndroidJunitRunnerSample/app/src/main/res/drawable-xhdpi/ic_launcher.png b/runner/AndroidJunitRunnerSample/app/src/main/res/drawable-xhdpi/ic_launcher.png similarity index 100% rename from testrunner/AndroidJunitRunnerSample/app/src/main/res/drawable-xhdpi/ic_launcher.png rename to runner/AndroidJunitRunnerSample/app/src/main/res/drawable-xhdpi/ic_launcher.png diff --git a/testrunner/AndroidJunitRunnerSample/app/src/main/res/drawable-xxhdpi/ic_launcher.png b/runner/AndroidJunitRunnerSample/app/src/main/res/drawable-xxhdpi/ic_launcher.png similarity index 100% rename from testrunner/AndroidJunitRunnerSample/app/src/main/res/drawable-xxhdpi/ic_launcher.png rename to runner/AndroidJunitRunnerSample/app/src/main/res/drawable-xxhdpi/ic_launcher.png diff --git a/testrunner/AndroidJunitRunnerSample/app/src/main/res/layout/activity_calculator.xml b/runner/AndroidJunitRunnerSample/app/src/main/res/layout/activity_calculator.xml similarity index 100% rename from testrunner/AndroidJunitRunnerSample/app/src/main/res/layout/activity_calculator.xml rename to runner/AndroidJunitRunnerSample/app/src/main/res/layout/activity_calculator.xml diff --git a/testrunner/AndroidJunitRunnerSample/app/src/main/res/values-v14/styles.xml b/runner/AndroidJunitRunnerSample/app/src/main/res/values-v14/styles.xml similarity index 100% rename from testrunner/AndroidJunitRunnerSample/app/src/main/res/values-v14/styles.xml rename to runner/AndroidJunitRunnerSample/app/src/main/res/values-v14/styles.xml diff --git a/testrunner/AndroidJunitRunnerSample/app/src/main/res/values-v21/styles.xml b/runner/AndroidJunitRunnerSample/app/src/main/res/values-v21/styles.xml similarity index 100% rename from testrunner/AndroidJunitRunnerSample/app/src/main/res/values-v21/styles.xml rename to runner/AndroidJunitRunnerSample/app/src/main/res/values-v21/styles.xml diff --git a/integrationtesting/ServiceTestRuleSample/app/src/main/res/values-w820dp/dimens.xml b/runner/AndroidJunitRunnerSample/app/src/main/res/values-w820dp/dimens.xml similarity index 100% rename from integrationtesting/ServiceTestRuleSample/app/src/main/res/values-w820dp/dimens.xml rename to runner/AndroidJunitRunnerSample/app/src/main/res/values-w820dp/dimens.xml diff --git a/testrunner/AndroidJunitRunnerSample/app/src/main/res/values/dimens.xml b/runner/AndroidJunitRunnerSample/app/src/main/res/values/dimens.xml similarity index 100% rename from testrunner/AndroidJunitRunnerSample/app/src/main/res/values/dimens.xml rename to runner/AndroidJunitRunnerSample/app/src/main/res/values/dimens.xml diff --git a/testrunner/AndroidJunitRunnerSample/app/src/main/res/values/strings.xml b/runner/AndroidJunitRunnerSample/app/src/main/res/values/strings.xml similarity index 100% rename from testrunner/AndroidJunitRunnerSample/app/src/main/res/values/strings.xml rename to runner/AndroidJunitRunnerSample/app/src/main/res/values/strings.xml diff --git a/testrunner/AndroidJunitRunnerSample/app/src/main/res/values/styles.xml b/runner/AndroidJunitRunnerSample/app/src/main/res/values/styles.xml similarity index 100% rename from testrunner/AndroidJunitRunnerSample/app/src/main/res/values/styles.xml rename to runner/AndroidJunitRunnerSample/app/src/main/res/values/styles.xml diff --git a/runner/AndroidJunitRunnerSample/build.gradle b/runner/AndroidJunitRunnerSample/build.gradle new file mode 100644 index 000000000..2ae25590d --- /dev/null +++ b/runner/AndroidJunitRunnerSample/build.gradle @@ -0,0 +1,36 @@ +// Top-level build file where you can add configuration options common to all sub-projects/modules. + +buildscript { + ext.agpVersion = "8.5.0" + repositories { + // Insert local test repo here + google() + mavenCentral() + } + dependencies { + classpath "com.android.tools.build:gradle:$agpVersion" + + // NOTE: Do not place your application dependencies here; they belong + // in the individual module build.gradle files + } +} + +allprojects { + repositories { + // Insert local test repo here + google() + mavenCentral() + } +} + +ext { + buildToolsVersion = "32.0.0" + androidxAnnotationVersion = "1.5.0" + guavaVersion = "31.1-android" + coreVersion = "1.6.1" + extJUnitVersion = "1.2.1" + runnerVersion = "1.6.1" + rulesVersion = "1.6.1" + espressoVersion = "3.6.1" + truthVersion = "1.1.3" +} diff --git a/runner/AndroidJunitRunnerSample/gradle.properties b/runner/AndroidJunitRunnerSample/gradle.properties new file mode 100644 index 000000000..be3166792 --- /dev/null +++ b/runner/AndroidJunitRunnerSample/gradle.properties @@ -0,0 +1,23 @@ +# 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. +# Default value: -Xmx10248m -XX:MaxPermSize=256m +# org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8 + +# 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 +android.defaults.buildfeatures.buildconfig=true +android.nonFinalResIds=false +android.nonTransitiveRClass=false +android.useAndroidX=true +android.useAndroidX=true diff --git a/runner/AndroidJunitRunnerSample/gradle/wrapper/gradle-wrapper.jar b/runner/AndroidJunitRunnerSample/gradle/wrapper/gradle-wrapper.jar new file mode 100644 index 000000000..41d9927a4 Binary files /dev/null and b/runner/AndroidJunitRunnerSample/gradle/wrapper/gradle-wrapper.jar differ diff --git a/espresso/CustomMatcherSample/gradle/wrapper/gradle-wrapper.properties b/runner/AndroidJunitRunnerSample/gradle/wrapper/gradle-wrapper.properties similarity index 80% rename from espresso/CustomMatcherSample/gradle/wrapper/gradle-wrapper.properties rename to runner/AndroidJunitRunnerSample/gradle/wrapper/gradle-wrapper.properties index 0c71e760d..48c0a02ca 100644 --- a/espresso/CustomMatcherSample/gradle/wrapper/gradle-wrapper.properties +++ b/runner/AndroidJunitRunnerSample/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,5 @@ -#Wed Apr 10 15:27:10 PDT 2013 distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists +distributionUrl=https\://services.gradle.org/distributions/gradle-8.7-bin.zip zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-2.2.1-all.zip diff --git a/runner/AndroidJunitRunnerSample/gradlew b/runner/AndroidJunitRunnerSample/gradlew new file mode 100755 index 000000000..1b6c78733 --- /dev/null +++ b/runner/AndroidJunitRunnerSample/gradlew @@ -0,0 +1,234 @@ +#!/bin/sh + +# +# Copyright © 2015-2021 the original authors. +# +# 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 +# +# https://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. +# + +############################################################################## +# +# Gradle start up script for POSIX generated by Gradle. +# +# Important for running: +# +# (1) You need a POSIX-compliant shell to run this script. If your /bin/sh is +# noncompliant, but you have some other compliant shell such as ksh or +# bash, then to run this script, type that shell name before the whole +# command line, like: +# +# ksh Gradle +# +# Busybox and similar reduced shells will NOT work, because this script +# requires all of these POSIX shell features: +# * functions; +# * expansions «$var», «${var}», «${var:-default}», «${var+SET}», +# «${var#prefix}», «${var%suffix}», and «$( cmd )»; +# * compound commands having a testable exit status, especially «case»; +# * various built-in commands including «command», «set», and «ulimit». +# +# Important for patching: +# +# (2) This script targets any POSIX shell, so it avoids extensions provided +# by Bash, Ksh, etc; in particular arrays are avoided. +# +# The "traditional" practice of packing multiple parameters into a +# space-separated string is a well documented source of bugs and security +# problems, so this is (mostly) avoided, by progressively accumulating +# options in "$@", and eventually passing that to Java. +# +# Where the inherited environment variables (DEFAULT_JVM_OPTS, JAVA_OPTS, +# and GRADLE_OPTS) rely on word-splitting, this is performed explicitly; +# see the in-line comments for details. +# +# There are tweaks for specific operating systems such as AIX, CygWin, +# Darwin, MinGW, and NonStop. +# +# (3) This script is generated from the Groovy template +# https://github.com/gradle/gradle/blob/master/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt +# within the Gradle project. +# +# You can find Gradle at https://github.com/gradle/gradle/. +# +############################################################################## + +# Attempt to set APP_HOME + +# Resolve links: $0 may be a link +app_path=$0 + +# Need this for daisy-chained symlinks. +while + APP_HOME=${app_path%"${app_path##*/}"} # leaves a trailing /; empty if no leading path + [ -h "$app_path" ] +do + ls=$( ls -ld "$app_path" ) + link=${ls#*' -> '} + case $link in #( + /*) app_path=$link ;; #( + *) app_path=$APP_HOME$link ;; + esac +done + +APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit + +APP_NAME="Gradle" +APP_BASE_NAME=${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='"-Xmx64m" "-Xms64m"' + +# Use the maximum available, or set MAX_FD != -1 to use that value. +MAX_FD=maximum + +warn () { + echo "$*" +} >&2 + +die () { + echo + echo "$*" + echo + exit 1 +} >&2 + +# 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 ;; #( + MSYS* | 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" && ! "$darwin" && ! "$nonstop" ; then + case $MAX_FD in #( + max*) + MAX_FD=$( ulimit -H -n ) || + warn "Could not query maximum file descriptor limit" + esac + case $MAX_FD in #( + '' | soft) :;; #( + *) + ulimit -n "$MAX_FD" || + warn "Could not set maximum file descriptor limit to $MAX_FD" + esac +fi + +# Collect all arguments for the java command, stacking in reverse order: +# * args from the command line +# * the main class name +# * -classpath +# * -D...appname settings +# * --module-path (only if needed) +# * DEFAULT_JVM_OPTS, JAVA_OPTS, and GRADLE_OPTS environment variables. + +# For Cygwin or MSYS, switch paths to Windows format before running java +if "$cygwin" || "$msys" ; then + APP_HOME=$( cygpath --path --mixed "$APP_HOME" ) + CLASSPATH=$( cygpath --path --mixed "$CLASSPATH" ) + + JAVACMD=$( cygpath --unix "$JAVACMD" ) + + # Now convert the arguments - kludge to limit ourselves to /bin/sh + for arg do + if + case $arg in #( + -*) false ;; # don't mess with options #( + /?*) t=${arg#/} t=/${t%%/*} # looks like a POSIX filepath + [ -e "$t" ] ;; #( + *) false ;; + esac + then + arg=$( cygpath --path --ignore --mixed "$arg" ) + fi + # Roll the args list around exactly as many times as the number of + # args, so each arg winds up back in the position where it started, but + # possibly modified. + # + # NB: a `for` loop captures its iteration list before it begins, so + # changing the positional parameters here affects neither the number of + # iterations, nor the values presented in `arg`. + shift # remove old arg + set -- "$@" "$arg" # push replacement arg + done +fi + +# Collect all arguments for the java command; +# * $DEFAULT_JVM_OPTS, $JAVA_OPTS, and $GRADLE_OPTS can contain fragments of +# shell script including quotes and variable substitutions, so put them in +# double quotes to make sure that they get re-expanded; and +# * put everything else in single quotes, so that it's not re-expanded. + +set -- \ + "-Dorg.gradle.appname=$APP_BASE_NAME" \ + -classpath "$CLASSPATH" \ + org.gradle.wrapper.GradleWrapperMain \ + "$@" + +# Use "xargs" to parse quoted args. +# +# With -n1 it outputs one arg per line, with the quotes and backslashes removed. +# +# In Bash we could simply go: +# +# readarray ARGS < <( xargs -n1 <<<"$var" ) && +# set -- "${ARGS[@]}" "$@" +# +# but POSIX shell has neither arrays nor command substitution, so instead we +# post-process each arg (as a line of input to sed) to backslash-escape any +# character that might be a shell metacharacter, then use eval to reverse +# that process (while maintaining the separation between arguments), and wrap +# the whole thing up as a single "set" statement. +# +# This will of course break if any of these variables contains a newline or +# an unmatched quote. +# + +eval "set -- $( + printf '%s\n' "$DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS" | + xargs -n1 | + sed ' s~[^-[:alnum:]+,./:=@_]~\\&~g; ' | + tr '\n' ' ' + )" '"$@"' + +exec "$JAVACMD" "$@" diff --git a/espresso/CustomMatcherSample/gradlew.bat b/runner/AndroidJunitRunnerSample/gradlew.bat similarity index 64% rename from espresso/CustomMatcherSample/gradlew.bat rename to runner/AndroidJunitRunnerSample/gradlew.bat index aec99730b..ac1b06f93 100644 --- a/espresso/CustomMatcherSample/gradlew.bat +++ b/runner/AndroidJunitRunnerSample/gradlew.bat @@ -1,3 +1,19 @@ +@rem +@rem Copyright 2015 the original author or authors. +@rem +@rem Licensed under the Apache License, Version 2.0 (the "License"); +@rem you may not use this file except in compliance with the License. +@rem You may obtain a copy of the License at +@rem +@rem https://www.apache.org/licenses/LICENSE-2.0 +@rem +@rem Unless required by applicable law or agreed to in writing, software +@rem distributed under the License is distributed on an "AS IS" BASIS, +@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +@rem See the License for the specific language governing permissions and +@rem limitations under the License. +@rem + @if "%DEBUG%" == "" @echo off @rem ########################################################################## @rem @@ -8,20 +24,23 @@ @rem Set local scope for the variables with windows NT shell if "%OS%"=="Windows_NT" setlocal -@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= - set DIRNAME=%~dp0 if "%DIRNAME%" == "" set DIRNAME=. set APP_BASE_NAME=%~n0 set APP_HOME=%DIRNAME% +@rem Resolve any "." and ".." in APP_HOME to make it shorter. +for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi + +@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="-Xmx64m" "-Xms64m" + @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 +if "%ERRORLEVEL%" == "0" goto execute echo. echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. @@ -35,7 +54,7 @@ goto fail set JAVA_HOME=%JAVA_HOME:"=% set JAVA_EXE=%JAVA_HOME%/bin/java.exe -if exist "%JAVA_EXE%" goto init +if exist "%JAVA_EXE%" goto execute echo. echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% @@ -45,34 +64,14 @@ echo location of your Java installation. goto fail -:init -@rem Get command-line arguments, handling Windowz variants - -if not "%OS%" == "Windows_NT" goto win9xME_args -if "%@eval[2+2]" == "4" goto 4NT_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=%* -goto execute - -:4NT_args -@rem Get arguments from the 4NT Shell from JP Software -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% +"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %* :end @rem End local scope for the variables with windows NT shell diff --git a/espresso/CustomMatcherSample/settings.gradle b/runner/AndroidJunitRunnerSample/settings.gradle similarity index 100% rename from espresso/CustomMatcherSample/settings.gradle rename to runner/AndroidJunitRunnerSample/settings.gradle diff --git a/runner/AndroidTestOrchestratorSample/.gitignore b/runner/AndroidTestOrchestratorSample/.gitignore new file mode 100644 index 000000000..03eee2ade --- /dev/null +++ b/runner/AndroidTestOrchestratorSample/.gitignore @@ -0,0 +1,6 @@ +.gradle +/local.properties +.idea +*.iml +.DS_Store +build diff --git a/runner/AndroidTestOrchestratorSample/README.md b/runner/AndroidTestOrchestratorSample/README.md new file mode 100644 index 000000000..4ac8bdd45 --- /dev/null +++ b/runner/AndroidTestOrchestratorSample/README.md @@ -0,0 +1,28 @@ +# AndroidTestOrchestrator sample + +The Android Test Orchestrator allows you to run each of your app's tests in isolation, enabling greater relability. +See https://developer.android.com/training/testing/junit-runner#using-android-test-orchestrator for more background. + +This sample is a subset of the AndroidJUnitRunner sample, but it +illustrates how to enable the Android Test Orchestrator in the app/build.gradle file. + +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*). +1. In Android Studio, select *File* | *Open...* and point to the top-level `./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. Create the test configuration + * Open *Run* menu | *Edit Configurations* + * Add a new *Android Tests* configuration + * Choose a module +1. Connect a device or start an emulator + * Turn animations off. + (On your device, under Settings->Developer options disable the following 3 settings: "Window animation scale", "Transition animation scale" and "Animator duration scale") +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/runner/AndroidTestOrchestratorSample/app/build.gradle b/runner/AndroidTestOrchestratorSample/app/build.gradle new file mode 100644 index 000000000..ddd122498 --- /dev/null +++ b/runner/AndroidTestOrchestratorSample/app/build.gradle @@ -0,0 +1,56 @@ +apply plugin: "com.android.application" + +android { + compileSdk 34 + defaultConfig { + applicationId "com.example.android.testing.androidtestorchestratorsample" + minSdkVersion 21 + targetSdkVersion 34 + versionCode 1 + versionName "1.0" + + testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" + testInstrumentationRunnerArguments clearPackageData: "true" + } + buildTypes { + release { + minifyEnabled false + proguardFiles getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro" + } + } + productFlavors { + } + + testOptions { + execution "ANDROIDX_TEST_ORCHESTRATOR" + 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.androidtestorchestratorsample" +} + +dependencies { + // App's dependencies, including test + 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:monitor:" + rootProject.monitorVersion; + androidTestImplementation "androidx.test.espresso:espresso-core:" + rootProject.espressoVersion; + androidTestImplementation "com.google.truth:truth:" + rootProject.truthVersion; + androidTestUtil "androidx.test:orchestrator:" + rootProject.orchestratorVersion; + +} diff --git a/testrunner/AndroidJunitRunnerSample/app/src/androidTest/java/com/example/android/testing/androidjunitrunnersample/CalculatorAddParameterizedTest.java b/runner/AndroidTestOrchestratorSample/app/src/androidTest/java/com/example/android/testing/androidtestorchestratorsample/CalculatorAddParameterizedTest.java similarity index 87% rename from testrunner/AndroidJunitRunnerSample/app/src/androidTest/java/com/example/android/testing/androidjunitrunnersample/CalculatorAddParameterizedTest.java rename to runner/AndroidTestOrchestratorSample/app/src/androidTest/java/com/example/android/testing/androidtestorchestratorsample/CalculatorAddParameterizedTest.java index 65d0f034c..6730ecd6b 100644 --- a/testrunner/AndroidJunitRunnerSample/app/src/androidTest/java/com/example/android/testing/androidjunitrunnersample/CalculatorAddParameterizedTest.java +++ b/runner/AndroidTestOrchestratorSample/app/src/androidTest/java/com/example/android/testing/androidtestorchestratorsample/CalculatorAddParameterizedTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2015, The Android Open Source Project + * Copyright 2020, 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. @@ -14,21 +14,20 @@ * limitations under the License. */ -package com.example.android.testing.androidjunitrunnersample; +package com.example.android.testing.androidtestorchestratorsample; + +import static com.google.common.truth.Truth.assertThat; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; import org.junit.runners.Parameterized; -import android.test.suitebuilder.annotation.SmallTest; +import androidx.test.filters.SmallTest; import java.lang.Iterable; import java.util.Arrays; -import static org.hamcrest.CoreMatchers.equalTo; -import static org.hamcrest.CoreMatchers.is; -import static org.junit.Assert.assertThat; import static org.junit.runners.Parameterized.Parameters; @@ -74,6 +73,7 @@ public static Iterable data() { */ public CalculatorAddParameterizedTest(double operandOne, double operandTwo, double expectedResult) { + mOperandOne = operandOne; mOperandTwo = operandTwo; mExpectedResult = expectedResult; @@ -87,7 +87,6 @@ public void setUp() { @Test public void testAdd_TwoNumbers() { double resultAdd = mCalculator.add(mOperandOne, mOperandTwo); - assertThat(resultAdd, is(equalTo(mExpectedResult))); + assertThat(resultAdd).isEqualTo(mExpectedResult); } - } \ No newline at end of file diff --git a/runner/AndroidTestOrchestratorSample/app/src/androidTest/java/com/example/android/testing/androidtestorchestratorsample/CalculatorInstrumentationTest.java b/runner/AndroidTestOrchestratorSample/app/src/androidTest/java/com/example/android/testing/androidtestorchestratorsample/CalculatorInstrumentationTest.java new file mode 100644 index 000000000..95de2fb8a --- /dev/null +++ b/runner/AndroidTestOrchestratorSample/app/src/androidTest/java/com/example/android/testing/androidtestorchestratorsample/CalculatorInstrumentationTest.java @@ -0,0 +1,111 @@ +/* + * Copyright 2020, 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.androidtestorchestratorsample; + +import androidx.test.platform.graphics.HardwareRendererCompat; +import junit.framework.TestSuite; + +import org.junit.Before; +import org.junit.Test; +import org.junit.internal.builders.AllDefaultPossibilitiesBuilder; +import org.junit.runner.RunWith; + +import androidx.test.core.app.ActivityScenario; +import androidx.test.ext.junit.runners.AndroidJUnit4; +import androidx.test.filters.LargeTest; +import androidx.test.runner.AndroidJUnitRunner; + +import static androidx.test.core.app.ApplicationProvider.getApplicationContext; +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; + +/** + * JUnit4 Ui Tests for {@link CalculatorActivity} using the {@link AndroidJUnitRunner} with the + * Android Test Orchestrator. + * This class uses the JUnit4 syntax for tests. + *

+ * With the new AndroidJUnit runner you can run both JUnit3 and JUnit4 tests in a single test + * suite. The {@link AndroidRunnerBuilder} which extends JUnit's + * {@link AllDefaultPossibilitiesBuilder} will create a single {@link + * TestSuite} from all tests and run them. + */ +@RunWith(AndroidJUnit4.class) +@LargeTest +public class CalculatorInstrumentationTest { + + /** + * Use {@link ActivityScenario} to create and launch of the activity. + */ + @Before + public void launchActivity() { + ActivityScenario.launch(CalculatorActivity.class); + } + + @Test + public void noOperandShowsComputationError() { + final String expectedResult = getApplicationContext().getString(R.string.computationError); + onView(withId(R.id.operation_add_btn)).perform(click()); + onView(withId(R.id.operation_result_text_view)).check(matches(withText(expectedResult))); + } + + @Test + public void typeOperandsAndPerformAddOperation() { + performOperation(R.id.operation_add_btn, "16.0", "16.0", "32.0"); + } + + @Test + public void typeOperandsAndPerformSubOperation() { + performOperation(R.id.operation_sub_btn, "32.0", "16.0", "16.0"); + } + + @Test + public void typeOperandsAndPerformDivOperation() { + performOperation(R.id.operation_div_btn, "128.0", "16.0", "8.0"); + } + + @Test + public void divZeroForOperandTwoShowsError() { + final String expectedResult = getApplicationContext().getString(R.string.computationError); + performOperation(R.id.operation_div_btn, "128.0", "0.0", expectedResult); + } + + @Test + public void typeOperandsAndPerformMulOperation() { + performOperation(R.id.operation_mul_btn, "16.0", "16.0", "256.0"); + } + + private void performOperation(int btnOperationResId, String operandOne, + String operandTwo, String expectedResult) { + // Type the two operands in the EditText fields + onView(withId(R.id.operand_one_edit_text)).perform(typeText(operandOne), + closeSoftKeyboard()); + onView(withId(R.id.operand_two_edit_text)).perform(typeText(operandTwo), + closeSoftKeyboard()); + + // Click on a given operation button + onView(withId(btnOperationResId)).perform(click()); + + // Check the expected test is displayed in the Ui + onView(withId(R.id.operation_result_text_view)).check(matches(withText(expectedResult))); + } + +} diff --git a/runner/AndroidTestOrchestratorSample/app/src/main/AndroidManifest.xml b/runner/AndroidTestOrchestratorSample/app/src/main/AndroidManifest.xml new file mode 100644 index 000000000..aeed9db04 --- /dev/null +++ b/runner/AndroidTestOrchestratorSample/app/src/main/AndroidManifest.xml @@ -0,0 +1,36 @@ + + + + + + + + + + + + + + + + diff --git a/runner/AndroidTestOrchestratorSample/app/src/main/java/com/example/android/testing/androidtestorchestratorsample/Calculator.java b/runner/AndroidTestOrchestratorSample/app/src/main/java/com/example/android/testing/androidtestorchestratorsample/Calculator.java new file mode 100644 index 000000000..b7a17d12e --- /dev/null +++ b/runner/AndroidTestOrchestratorSample/app/src/main/java/com/example/android/testing/androidtestorchestratorsample/Calculator.java @@ -0,0 +1,57 @@ +/* + * Copyright 2020, 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.androidtestorchestratorsample; + +import static com.google.common.base.Preconditions.checkArgument; + +/** + * A simple calculator with a basic set of operations. + */ +public class Calculator { + + public enum Operator {ADD, SUB, DIV, MUL} + + /** + * Addition operation + */ + public double add(double firstOperand, double secondOperand) { + return firstOperand + secondOperand; + } + + /** + * Substract operation + */ + public double sub(double firstOperand, double secondOperand) { + return firstOperand - secondOperand; + } + + /** + * Divide operation + */ + public double div(double firstOperand, double secondOperand) { + checkArgument(secondOperand != 0, "secondOperand must be != 0, you cannot divide by zero"); + return firstOperand / secondOperand; + } + + /** + * Multiply operation + */ + public double mul(double firstOperand, double secondOperand) { + + return firstOperand * secondOperand; + } +} diff --git a/runner/AndroidTestOrchestratorSample/app/src/main/java/com/example/android/testing/androidtestorchestratorsample/CalculatorActivity.java b/runner/AndroidTestOrchestratorSample/app/src/main/java/com/example/android/testing/androidtestorchestratorsample/CalculatorActivity.java new file mode 100644 index 000000000..d745a3210 --- /dev/null +++ b/runner/AndroidTestOrchestratorSample/app/src/main/java/com/example/android/testing/androidtestorchestratorsample/CalculatorActivity.java @@ -0,0 +1,138 @@ +/* + * Copyright 2020, 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.androidtestorchestratorsample; + +import android.app.Activity; +import android.os.Bundle; +import android.text.TextUtils; +import android.util.Log; +import android.view.View; +import android.widget.Button; +import android.widget.EditText; +import android.widget.TextView; + +/** + * {@link android.app.Activity} which contains a simple calculator. Numbers can be entered in the + * two {@link EditText} fields and result can be obtained by pressing one of the + * operation {@link Button}s at the bottom. + */ +public class CalculatorActivity extends Activity { + + private static final String TAG = "CalculatorActivity"; + + private Calculator mCalculator; + + private EditText mOperandOneEditText; + private EditText mOperandTwoEditText; + + private TextView mResultTextView; + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_calculator); + mCalculator = new Calculator(); + mResultTextView = (TextView) findViewById(R.id.operation_result_text_view); + mOperandOneEditText = (EditText) findViewById(R.id.operand_one_edit_text); + mOperandTwoEditText = (EditText) findViewById(R.id.operand_two_edit_text); + } + + /** + * OnClick method that is called when the add {@link Button} is pressed. + */ + public void onAdd(View view) { + compute(Calculator.Operator.ADD); + } + + /** + * OnClick method that is called when the substract {@link Button} is pressed. + */ + public void onSub(View view) { + compute(Calculator.Operator.SUB); + } + + /** + * OnClick method that is called when the divide {@link Button} is pressed. + */ + public void onDiv(View view) { + try { + compute(Calculator.Operator.DIV); + } catch (IllegalArgumentException iae) { + Log.e(TAG, "IllegalArgumentException", iae); + mResultTextView.setText(getString(R.string.computationError)); + } + } + + /** + * OnClick method that is called when the multiply {@link Button} is pressed. + */ + public void onMul(View view) { + compute(Calculator.Operator.MUL); + } + + private void compute(Calculator.Operator operator) { + double operandOne; + double operandTwo; + try { + operandOne = getOperand(mOperandOneEditText); + operandTwo = getOperand(mOperandTwoEditText); + } catch (NumberFormatException nfe) { + Log.e(TAG, "NumberFormatException", nfe); + mResultTextView.setText(getString(R.string.computationError)); + return; + } + + String result; + switch (operator) { + case ADD: + result = String.valueOf(mCalculator.add(operandOne, operandTwo)); + break; + case SUB: + result = String.valueOf(mCalculator.sub(operandOne, operandTwo)); + break; + case DIV: + result = String.valueOf(mCalculator.div(operandOne, operandTwo)); + break; + case MUL: + result = String.valueOf(mCalculator.mul(operandOne, operandTwo)); + break; + default: + result = getString(R.string.computationError); + break; + } + mResultTextView.setText(result); + } + + /** + * @return the operand value which was entered in an {@link EditText} as a double + */ + private static Double getOperand(EditText operandEditText) { + String operandText = getOperandText(operandEditText); + return Double.valueOf(operandText); + } + + /** + * @return the operand text which was entered in an {@link EditText}. + */ + private static String getOperandText(EditText operandEditText) { + String operandText = operandEditText.getText().toString(); + if (TextUtils.isEmpty(operandText)) { + throw new NumberFormatException("operand cannot be empty!"); + } + return operandText; + } +} diff --git a/runner/AndroidTestOrchestratorSample/app/src/main/res/drawable-hdpi/ic_launcher.png b/runner/AndroidTestOrchestratorSample/app/src/main/res/drawable-hdpi/ic_launcher.png new file mode 100755 index 000000000..965ac9624 Binary files /dev/null and b/runner/AndroidTestOrchestratorSample/app/src/main/res/drawable-hdpi/ic_launcher.png differ diff --git a/runner/AndroidTestOrchestratorSample/app/src/main/res/drawable-mdpi/ic_launcher.png b/runner/AndroidTestOrchestratorSample/app/src/main/res/drawable-mdpi/ic_launcher.png new file mode 100755 index 000000000..df52c5278 Binary files /dev/null and b/runner/AndroidTestOrchestratorSample/app/src/main/res/drawable-mdpi/ic_launcher.png differ diff --git a/runner/AndroidTestOrchestratorSample/app/src/main/res/drawable-xhdpi/ic_launcher.png b/runner/AndroidTestOrchestratorSample/app/src/main/res/drawable-xhdpi/ic_launcher.png new file mode 100755 index 000000000..3d479bfe7 Binary files /dev/null and b/runner/AndroidTestOrchestratorSample/app/src/main/res/drawable-xhdpi/ic_launcher.png differ diff --git a/runner/AndroidTestOrchestratorSample/app/src/main/res/drawable-xxhdpi/ic_launcher.png b/runner/AndroidTestOrchestratorSample/app/src/main/res/drawable-xxhdpi/ic_launcher.png new file mode 100755 index 000000000..c85d90b05 Binary files /dev/null and b/runner/AndroidTestOrchestratorSample/app/src/main/res/drawable-xxhdpi/ic_launcher.png differ diff --git a/runner/AndroidTestOrchestratorSample/app/src/main/res/layout/activity_calculator.xml b/runner/AndroidTestOrchestratorSample/app/src/main/res/layout/activity_calculator.xml new file mode 100644 index 000000000..60f5e3565 --- /dev/null +++ b/runner/AndroidTestOrchestratorSample/app/src/main/res/layout/activity_calculator.xml @@ -0,0 +1,82 @@ + + + + + + + + + + + +