-
Notifications
You must be signed in to change notification settings - Fork 3.7k
Add a testing sample for Espresso Device #449
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
e83318e
Add testing sample for Espresso Device
92d9c5f
Add testing sample for Espresso Device
8c821b7
Add testing sample for Espresso Device
02a642e
Add testing sample for Espresso Device
f729369
Undo new line at end of projects.conf
kmcauliffe6 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| .gradle | ||
| local.properties | ||
| .idea | ||
| .DS_Store | ||
| build | ||
| *.iml |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,58 @@ | ||
| licenses(["notice"]) # Apache 2.0 | ||
|
|
||
| load("//:common_defs.bzl", "minSdkVersion", "targetSdkVersion") | ||
| load("@rules_jvm_external//:defs.bzl", "artifact") | ||
|
|
||
| android_library( | ||
| name = "EspressoDeviceSampleLib", | ||
| srcs = glob(["app/src/main/**/*.java"]), | ||
| custom_package = "com.example.android.testing.espresso.EspressoDeviceSample", | ||
| manifest = "app/src/main/AndroidManifest.xml", | ||
| resource_files = glob(["app/src/main/res/**/*"]), | ||
| ) | ||
|
|
||
| android_binary( | ||
| name = "EspressoDeviceSample", | ||
| custom_package = "com.example.android.testing.espresso.EspressoDeviceSample", | ||
| manifest = "app/src/main/AppManifest.xml", | ||
| manifest_values = { | ||
| "minSdkVersion": minSdkVersion, | ||
| "targetSdkVersion": targetSdkVersion, | ||
| }, | ||
| deps = [":EspressoDeviceSampleLib"], | ||
| ) | ||
|
|
||
| android_library( | ||
| name = "EspressoDeviceSampleTestLib", | ||
| srcs = glob(["app/src/androidTest/**/*.java"]), | ||
| custom_package = "com.example.android.testing.espresso.EspressoDeviceSample.test", | ||
| deps = [ | ||
| ":EspressoDeviceSampleLib", | ||
| "//:test_deps", | ||
| ], | ||
| ) | ||
|
|
||
| android_binary( | ||
| name = "EspressoDeviceSampleTest", | ||
| custom_package = "com.example.android.testing.espresso.EspressoDeviceSample.test", | ||
| instruments = ":EspressoDeviceSample", | ||
| manifest = "app/src/androidTest/AndroidManifest.xml", | ||
| manifest_values = { | ||
| "minSdkVersion": minSdkVersion, | ||
| "targetSdkVersion": targetSdkVersion, | ||
| }, | ||
| deps = [":EspressoDeviceSampleTestLib"], | ||
| ) | ||
|
|
||
| API_LEVELS = [ | ||
| "19_x86", | ||
| "21_x86", | ||
| "22_x86", | ||
| "23_x86", | ||
| ] | ||
|
|
||
| [android_instrumentation_test( | ||
| name = "EspressoDeviceSampleInstrumentationTest_%s" % API_LEVEL, | ||
| target_device = "@android_test_support//tools/android/emulated_devices/generic_phone:android_%s_qemu2" % API_LEVEL, | ||
| test_app = ":EspressoDeviceSampleTest", | ||
| ) for API_LEVEL in API_LEVELS] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| # Basic sample for Espresso Device | ||
|
|
||
| The Espresso Device API enables synchronized interactions with the test device. This API is experimental and subject to change. Currently, it is only supported on instrumentation tests run on emulators. | ||
|
|
||
| To skip tests on devices that do not have certain display attributes, such as display width and height, annotate your test with @RequiresDisplay. This annotation takes in a WidthSizeClassEnum and a HeightSizeClassEnum. It can be applied to test classes or test methods. For details on these size classes, see https://developer.android.com/guide/topics/large-screens/support-different-screen-sizes. | ||
|
|
||
| This project uses the Gradle build system. You don't need an IDE to build and execute it but Android Studio 3.4 is recommended. | ||
|
|
||
| 1. Download the project code, preferably using `git clone`. | ||
| 1. In Android Studio, select *File* | *Open...* and point to the `./build.gradle` file. | ||
| 1. Check out the relevant code: | ||
| * The application under test is located in `src/main/java` | ||
| * Instrumentation Tests are in `src/androidTest/java` | ||
| * Local Tests are in `src/test/java` | ||
| 1. Create and run the Instrumented test configuration | ||
| * Open *Run* menu | *Edit Configurations* | ||
| * Add a new *Android Instrumented Tests* configuration | ||
| * Choose the `app` module | ||
| * 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") | ||
| * 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. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,60 @@ | ||
| apply plugin: 'com.android.application' | ||
|
|
||
| apply plugin: 'kotlin-android' | ||
|
|
||
| apply plugin: 'kotlin-android-extensions' | ||
|
|
||
| android { | ||
| compileSdkVersion 33 | ||
| buildToolsVersion rootProject.buildToolsVersion | ||
| defaultConfig { | ||
| applicationId "com.example.android.testing.espresso.EspressoDeviceSample" | ||
| minSdkVersion 14 | ||
| targetSdkVersion 33 | ||
| versionCode 1 | ||
| versionName "1.0" | ||
|
|
||
| testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" | ||
| } | ||
| lintOptions { | ||
| abortOnError false | ||
| } | ||
| productFlavors { | ||
| } | ||
| testOptions { | ||
| unitTests { | ||
| includeAndroidResources = true | ||
| } | ||
| managedDevices { | ||
| devices { | ||
| // run with ../gradlew nexusOneApi30DebugAndroidTest | ||
| nexusOneApi30(com.android.build.api.dsl.ManagedVirtualDevice) { | ||
| // A lower resolution device is used here for better emulator performance | ||
| device = "Nexus One" | ||
| apiLevel = 30 | ||
| // Also use the AOSP ATD image for better emulator performance | ||
| // The androidx.test screenshot APIs will automatically enable hardware rendering | ||
| // to take a screenshot | ||
| systemImageSource = "aosp-atd" | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
||
| tasks.withType(org.jetbrains.kotlin.gradle.tasks.KotlinCompile).all { | ||
| kotlinOptions { | ||
| jvmTarget = "1.8" | ||
| } | ||
| } | ||
|
|
||
| dependencies { | ||
| androidTestImplementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlinVersion" | ||
| androidTestImplementation 'androidx.test.ext:junit:' + rootProject.extJUnitVersion | ||
| androidTestImplementation 'androidx.test.ext:junit-ktx:' + rootProject.extJUnitVersion | ||
| androidTestImplementation 'androidx.test.espresso:espresso-device:' + rootProject.espressoDeviceVersion | ||
|
|
||
| testImplementation 'androidx.test.ext:junit:' + rootProject.extJUnitVersion | ||
| testImplementation 'junit:junit:4.12' | ||
| testImplementation 'org.robolectric:robolectric:' + rootProject.robolectricVersion | ||
| } | ||
27 changes: 27 additions & 0 deletions
27
ui/espresso/EspressoDeviceSample/app/src/androidTest/AndroidManifest.xml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| <?xml version="1.0" encoding="utf-8"?> | ||
| <!-- | ||
| ~ Copyright (C) 2022 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. | ||
| --> | ||
| <manifest xmlns:android="http://schemas.android.com/apk/res/android" | ||
| xmlns:tools="http://schemas.android.com/tools" | ||
| package="com.example.android.testing.espresso.EspressoDeviceSample.test" | ||
| android:versionCode="1" | ||
| android:versionName="1.0"> | ||
|
|
||
| <instrumentation android:targetPackage="com.example.android.testing.espresso.EspressoDeviceSample" | ||
| android:name="androidx.test.runner.AndroidJUnitRunner"/> | ||
|
|
||
| <application tools:replace="label" android:label="EspressoDeviceSampleTest" /> | ||
| </manifest> |
93 changes: 93 additions & 0 deletions
93
...est/java/com/example/android/testing/espresso/EspressoDeviceSample/RequiresDisplayTest.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,93 @@ | ||
| /* | ||
| * Copyright 2022, 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.EspressoDeviceSample | ||
|
|
||
| import androidx.test.espresso.device.filter.RequiresDisplay | ||
| import androidx.test.espresso.device.sizeclass.HeightSizeClass | ||
| import androidx.test.espresso.device.sizeclass.WidthSizeClass | ||
| import androidx.test.ext.junit.runners.AndroidJUnit4 | ||
| import org.junit.Test | ||
| import org.junit.runner.RunWith | ||
|
|
||
| /* | ||
| * Illustrates usage of @RequiresDisplay API to filter tests based on display attributes such a screen size. | ||
| */ | ||
| @RunWith(AndroidJUnit4::class) | ||
| class RequiresDisplayTest { | ||
| @RequiresDisplay( | ||
| widthSizeClass = WidthSizeClass.Companion.WidthSizeClassEnum.COMPACT, | ||
| heightSizeClass = HeightSizeClass.Companion.HeightSizeClassEnum.COMPACT | ||
| ) | ||
| @Test | ||
| fun testOnDevicesWithCompactWidthAndHeight() {} | ||
|
|
||
| @RequiresDisplay( | ||
| widthSizeClass = WidthSizeClass.Companion.WidthSizeClassEnum.COMPACT, | ||
| heightSizeClass = HeightSizeClass.Companion.HeightSizeClassEnum.MEDIUM | ||
| ) | ||
| @Test | ||
| fun testOnDevicesWithCompactWidthAndMediumHeight() {} | ||
|
|
||
| @RequiresDisplay( | ||
| widthSizeClass = WidthSizeClass.Companion.WidthSizeClassEnum.MEDIUM, | ||
| heightSizeClass = HeightSizeClass.Companion.HeightSizeClassEnum.COMPACT | ||
| ) | ||
| @Test | ||
| fun testOnDevicesWithMediumWidthAndCompactHeight() {} | ||
|
|
||
| @RequiresDisplay( | ||
| widthSizeClass = WidthSizeClass.Companion.WidthSizeClassEnum.COMPACT, | ||
| heightSizeClass = HeightSizeClass.Companion.HeightSizeClassEnum.EXPANDED | ||
| ) | ||
| @Test | ||
| fun testOnDevicesWithCompactWidthAndExpandedHeight() {} | ||
|
|
||
| @RequiresDisplay( | ||
| widthSizeClass = WidthSizeClass.Companion.WidthSizeClassEnum.EXPANDED, | ||
| heightSizeClass = HeightSizeClass.Companion.HeightSizeClassEnum.COMPACT | ||
| ) | ||
| @Test | ||
| fun testOnDevicesWithExpandedWidthAndCompactHeight() {} | ||
|
|
||
| @RequiresDisplay( | ||
| widthSizeClass = WidthSizeClass.Companion.WidthSizeClassEnum.MEDIUM, | ||
| heightSizeClass = HeightSizeClass.Companion.HeightSizeClassEnum.MEDIUM | ||
| ) | ||
| @Test | ||
| fun testOnDevicesWithMediumWidthAndHeight() {} | ||
|
|
||
| @RequiresDisplay( | ||
| widthSizeClass = WidthSizeClass.Companion.WidthSizeClassEnum.EXPANDED, | ||
| heightSizeClass = HeightSizeClass.Companion.HeightSizeClassEnum.MEDIUM, | ||
| ) | ||
| @Test | ||
| fun testOnDevicesWithExpandedWidthAndMediumHeight() {} | ||
|
|
||
|
|
||
| @RequiresDisplay( | ||
| widthSizeClass = WidthSizeClass.Companion.WidthSizeClassEnum.MEDIUM, | ||
| heightSizeClass = HeightSizeClass.Companion.HeightSizeClassEnum.EXPANDED | ||
| ) | ||
| @Test | ||
| fun testOnDevicesWithMediumWidthAndExpandedHeight() {} | ||
|
|
||
| @RequiresDisplay( | ||
| widthSizeClass = WidthSizeClass.Companion.WidthSizeClassEnum.EXPANDED, | ||
| heightSizeClass = HeightSizeClass.Companion.HeightSizeClassEnum.EXPANDED | ||
| ) | ||
| @Test | ||
| fun testOnDevicesWithExpandedWidthAndHeight() {} | ||
| } |
36 changes: 36 additions & 0 deletions
36
ui/espresso/EspressoDeviceSample/app/src/main/AndroidManifest.xml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,36 @@ | ||
| <?xml version="1.0" encoding="utf-8"?> | ||
| <!-- | ||
| ~ Copyright (C) 2022 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. | ||
| --> | ||
|
|
||
| <manifest xmlns:android="http://schemas.android.com/apk/res/android" | ||
| package="com.example.android.testing.espresso.EspressoDeviceSample" > | ||
|
|
||
| <application | ||
| android:icon="@drawable/ic_launcher" | ||
| android:label="@string/app_name" | ||
| android:theme="@style/AppTheme" > | ||
| <activity | ||
| android:name="com.example.android.testing.espresso.EspressoDeviceSample.MainActivity" | ||
| android:label="@string/app_name" | ||
| android:exported="true"> | ||
| <intent-filter> | ||
| <action android:name="android.intent.action.MAIN" /> | ||
| <category android:name="android.intent.category.LAUNCHER" /> | ||
| </intent-filter> | ||
| </activity> | ||
| </application> | ||
|
|
||
| </manifest> |
22 changes: 22 additions & 0 deletions
22
ui/espresso/EspressoDeviceSample/app/src/main/AppManifest.xml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| <?xml version="1.0" encoding="utf-8"?> | ||
| <!-- | ||
| ~ Copyright (C) 2022 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. | ||
| --> | ||
|
|
||
| <manifest xmlns:android="http://schemas.android.com/apk/res/android" | ||
| package="com.example.android.testing.espresso.EspressoDeviceSample" > | ||
|
|
||
| <uses-sdk android:minSdkVersion="14" android:targetSdkVersion="28" /> | ||
| </manifest> |
31 changes: 31 additions & 0 deletions
31
...src/main/java/com/example/android/testing/espresso/EspressoDeviceSample/MainActivity.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| /* | ||
| * Copyright 2022, 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.EspressoDeviceSample; | ||
|
|
||
| import android.app.Activity; | ||
| import android.os.Bundle; | ||
|
|
||
| /** | ||
| * An empty {@link Activity} that Espresso Device APIs are tested against. | ||
| */ | ||
| public class MainActivity extends Activity { | ||
| @Override | ||
| protected void onCreate(Bundle savedInstanceState) { | ||
| super.onCreate(savedInstanceState); | ||
| setContentView(R.layout.activity_main); | ||
| } | ||
| } |
Binary file added
BIN
+2.04 KB
ui/espresso/EspressoDeviceSample/app/src/main/res/drawable-hdpi/ic_launcher.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+1.3 KB
ui/espresso/EspressoDeviceSample/app/src/main/res/drawable-mdpi/ic_launcher.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+2.73 KB
ui/espresso/EspressoDeviceSample/app/src/main/res/drawable-xhdpi/ic_launcher.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+4.33 KB
ui/espresso/EspressoDeviceSample/app/src/main/res/drawable-xxhdpi/ic_launcher.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+6.01 KB
ui/espresso/EspressoDeviceSample/app/src/main/res/drawable-xxxhdpi/ic_launcher.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can you add a gradle managed devices config too? You can copy from
testing-samples/ui/espresso/ScreenshotSample/app/build.gradle
Line 34 in f533f18
And add this project to projects.conf so its tested as part of release process
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.