• Stars
    star
    9,177
  • Rank 3,925 (Top 0.08 %)
  • Language
    Java
  • License
    Apache License 2.0
  • Created about 10 years ago
  • Updated 3 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A collection of samples demonstrating different frameworks and techniques for automated testing

Android testing samples

A collection of samples demonstrating different frameworks and techniques for automated testing.

Espresso Samples

BasicSample - Basic Espresso sample

CustomMatcherSample - Shows how to extend Espresso to match the hint property of an EditText

DataAdapterSample - Showcases the onData() entry point for Espresso, for lists and AdapterViews

FragmentScenarioSample - Basic usage of FragmentScenario with Espresso.

IdlingResourceSample - Synchronization with background jobs

IntentsBasicSample - Basic usage of intended() and intending()

IntentsAdvancedSample - Simulates a user fetching a bitmap using the camera

MultiWindowSample - Shows how to point Espresso to different windows

RecyclerViewSample - RecyclerView actions for Espresso

ScreenshotSample - Screenshot capturing and saving using Espresso and androidx.test.core APIs

WebBasicSample - Use Espresso-web to interact with WebViews

BasicSampleBundled - Basic sample for Eclipse and other IDEs

MultiProcessSample - Showcases how to use multiprocess Espresso.

UiAutomator Sample

BasicSample - Basic UI Automator sample

AndroidJUnitRunner Sample

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 - Simple usage of ActivityTestRule

IntentsBasicSample - Simple usage of IntentsTestRule

ServiceTestRuleSample - Simple usage of ServiceTestRule

Prerequisites

  • Android SDK v28
  • Android Build Tools v28.03

Getting Started

These samples use the Gradle build system. To build a project, enter the project directory and use the ./gradlew assemble command or use "Import Project" in Android Studio.

  • Use ./gradlew connectedAndroidTest to run the tests on a connected emulator or device.
  • Use ./gradlew test to run the unit test on your local host.

There is a top-level build.gradle file if you want to build and test all samples from the root directory. This is mostly helpful to build on a CI (Continuous Integration) server.

AndroidX Test Library

Many of these samples use the AndroidX Test Library. Visit the Testing site on developer.android.com for more information.

Experimental Bazel Support

Build status

Some of these samples can be tested with Bazel 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.

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. You may also want to check out Building an Android App with Bazel, and the list of Android Rules 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 repository instead of this repository.

Support

If you've found an error in this sample, please file an issue: https://github.com/googlesamples/android-testing

Patches are encouraged, and may be submitted by forking this project and submitting a pull request through GitHub. Please see CONTRIBUTING.md for more details.

License

Copyright 2015 The Android Open Source Project, Inc.

Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

More Repositories

1

architecture-samples

A collection of samples to discuss and showcase different architectural tools and patterns for Android apps.
Kotlin
44,270
star
2

architecture-components-samples

Samples for Android Architecture Components.
Kotlin
23,394
star
3

compose-samples

Official Jetpack Compose samples.
Kotlin
19,731
star
4

sunflower

A gardening app illustrating Android development best practices with migrating a View-based app to Jetpack Compose.
Kotlin
17,631
star
5

nowinandroid

A fully functional Android app built entirely with Kotlin and Jetpack Compose
Kotlin
16,685
star
6

uamp

A sample audio app for Android
Kotlin
13,078
star
7

ndk-samples

Android NDK samples with Android Studio
C++
10,078
star
8

android-ktx

A set of Kotlin extensions for Android app development.
7,470
star
9

topeka

A fun to play quiz that showcases material design on Android
Kotlin
5,164
star
10

views-widgets-samples

Multiple samples showing the best practices in views-widgets on Android.
Java
5,039
star
11

camera-samples

Multiple samples showing the best practices in camera APIs on Android.
Kotlin
4,943
star
12

user-interface-samples

Multiple samples showing the best practices in the user interface on Android.
Kotlin
4,358
star
13

location-samples

Multiple samples showing the best practices in location APIs on Android.
Kotlin
2,704
star
14

architecture-templates

2,661
star
15

animation-samples

Multiple samples showing the best practices in animation on Android.
Java
2,570
star
16

play-billing-samples

Samples for Google Play In-app Billing
Kotlin
2,375
star
17

ndk

The Android Native Development Kit
1,951
star
18

gradle-recipes

Ready-to-use recipes for common build customizations that showcase the Android Gradle plugin's public APIs and DSL.
Kotlin
1,912
star
19

kotlin-guides

A set of guides for writing Kotlin for Android.
HTML
1,690
star
20

databinding-samples

Kotlin
1,675
star
21

connectivity-samples

Multiple samples showing the best practices in connectivity on Android.
Java
1,638
star
22

storage-samples

Multiple samples showing the best practices in storage APIs on Android.
Kotlin
1,527
star
23

codelab-android-compose

Kotlin
1,411
star
24

media-samples

Multiple samples showing the best practices in media APIs on Android (audio, video, etc.).
Java
1,264
star
25

performance-samples

Samples to show APIs and best practices in Performance on Android
Kotlin
1,241
star
26

android-test

An extensive framework for testing Android apps
Java
1,158
star
27

wear-os-samples

Multiple samples showing best practices in app and watch face development on Wear OS.
Kotlin
1,095
star
28

tv-samples

Multiple samples showing best practices in app development on Android TV.
Kotlin
1,034
star
29

platform-samples

A collection of samples of different Android OS platform APIs.
Kotlin
1,022
star
30

security-samples

Multiple samples showing the best practices in security APIs on Android.
Kotlin
932
star
31

kotlin-multiplatform-samples

Samples showcasing the experimental Kotlin Multiplatform Jetpack libraries
Kotlin
898
star
32

codelab-android-room-with-a-view

Java
759
star
33

app-bundle-samples

Multiple samples showing the best practices in app bundles on Android.
C++
698
star
34

android-studio-poet

Large Android projects generator
Kotlin
697
star
35

trackr

Kotlin
659
star
36

codelab-android-navigation

Kotlin
634
star
37

codelab-android-lifecycles

Java
626
star
38

permissions-samples

Multiple samples showing the best practices in permissions on Android.
Kotlin
588
star
39

snippets

Main repository for snippets surfaced on developer.android.com.
Kotlin
572
star
40

codelab-kotlin-coroutines

Kotlin Coroutines codelab
Kotlin
550
star
41

codelab-android-workmanager

Kotlin
545
star
42

codelab-android-paging

Jetpack Paging codelab
Kotlin
494
star
43

codelab-constraint-layout

Constraint Layout Codelab
Java
471
star
44

enterprise-samples

Multiple samples showing the best practices in enterprise on Android.
Kotlin
385
star
45

renderscript-intrinsics-replacement-toolkit

Assembly
351
star
46

car-samples

Multiple samples showing best practices for car app development on both Android Auto and Android Automotive OS.
Java
351
star
47

codelab-android-hilt

Kotlin
350
star
48

socialite

Kotlin
340
star
49

identity-samples

Multiple samples showing the best practices in identity on Android.
Kotlin
335
star
50

graphics-samples

Multiple samples showing the best practices in graphics on Android.
Kotlin
309
star
51

input-samples

Multiple samples showing the best practices in input on Android.
Java
289
star
52

health-samples

Kotlin
262
star
53

codelab-android-datastore

Kotlin
226
star
54

codelab-exoplayer-intro

Media Streaming with ExoPlayer codelab
Kotlin
220
star
55

renderscript-samples

Multiple samples showing renderscript best practices in Android.
C++
218
star
56

games-samples

A collection of samples to discuss and showcase games in Android apps.
C++
211
star
57

codelab-android-dagger

Kotlin
181
star
58

codelab-mlkit-android

Kotlin
179
star
59

fit-samples

Multiple samples showing the best practices using the Fit APIs on Android.
Kotlin
152
star
60

sensors-samples

Multiple samples showing the best practices in sensors on Android.
Java
132
star
61

privacy-sandbox-samples

Kotlin
130
star
62

codelab-android-dynamic-features

Kotlin
120
star
63

project-replicator

This project contains a Gradle plugin and a small command-line app that allows replicating the structure of a given Gradle project.
Kotlin
116
star
64

codelab-android-accessibility

Basic Android Accessibility: making sure everyone can use what you create!
Java
110
star
65

android.github.io

HTML
108
star
66

codelab-android-databinding

Kotlin
102
star
67

codelab-android-dagger-to-hilt

Kotlin
93
star
68

codelab-while-in-use-location

Codelab:
Kotlin
81
star
69

security-certification-resources

Android Certification Tools
Java
80
star
70

codelab-fido2

Kotlin
78
star
71

codelab-android-network-security-config

Android Network Security Configuration codelab
Java
76
star
72

search-samples

Multiple samples demonstrating Search API usage in Android.
Kotlin
71
star
73

app-actions-samples

Samples demonstrating the use of App Actions
Kotlin
62
star
74

xAnd11

Kotlin
57
star
75

android-dev-challenge-compose

Template repository for the ADS22 Speed Challenge
Kotlin
53
star
76

tuningfork

Android Performance Tuner is a library to help developers measure frame rendering time across different devices and game stages. This plugin will help developers integrate Android Performance Tuner into their game.
C#
52
star
77

codelab-biometric-login

Kotlin
48
star
78

codelab-android-using-kotlin

Kotlin
48
star
79

people-messaging-codelab

Kotlin
45
star
80

midi-samples

Samples showing best practices for MIDI on Android.
Kotlin
43
star
81

codelab-android-wavemaker

Sample app which accompanies the "Making Waves" codelab - Part 1 Build a Synthesizer
C++
41
star
82

large-screen-codelabs

Kotlin
35
star
83

android-health-connect-codelab

Kotlin
34
star
84

codelab-slices-basic-codelab

Kotlin
29
star
85

codelab-activity_transitionapi

Codelab walks you through tracking activity transition changes (start/stop run, walk, idle, drive, etc.).
Java
24
star
86

gradle-declarative

Kotlin
24
star
87

neural-networks-samples

C++
23
star
88

codelab-android-foldable

Kotlin
21
star
89

codelab-android-performance

Kotlin
21
star
90

codelab-compose-for-wear-os

Learn how you can apply your knowledge of Compose to Wear OS
Kotlin
19
star
91

codelab-complications-data-source

Exposing data to watch face Complications on Android Wear
Kotlin
19
star
92

deep-links

Kotlin
19
star
93

tv-codelabs

Topic repo for Android TV codelabs
Kotlin
18
star
94

add-adaptive-layouts

Kotlin
18
star
95

rr

Android mirror of the rr debugger.
C++
18
star
96

car-codelabs

Kotlin
18
star
97

packager-manager-samples

Multiple samples demonstrating Package Manager in Android.
Kotlin
17
star
98

codelab-wear-tiles

Kotlin
17
star
99

privacy-codelab

Kotlin
16
star
100

adpf-unreal-plugin

C++
16
star