Skip to content
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

Add Test Configuration Sample #400

Open
wants to merge 21 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
0c9fdd2
[ConfigSample] Initial commit
JolandaVerhoef Sep 14, 2021
6f55b48
[ConfigSample] Add logging to gradle commands in Github Actions
JolandaVerhoef Sep 15, 2021
62d4253
[ConfigSample] Upgrade Gradle plugin and remove opt-in parameter
JolandaVerhoef Sep 16, 2021
d20a9b7
[ConfigSample] Change API level to 26 which is supported
JolandaVerhoef Sep 16, 2021
b121ae5
[ConfigSample] Try out caching
JolandaVerhoef Oct 6, 2021
a908ff1
[ConfigSample] Use wildcard in cache path
JolandaVerhoef Oct 7, 2021
1c5241b
[ConfigSample] Use ubuntu image as hardware acceleration is not needed
JolandaVerhoef Oct 7, 2021
7899cc5
[ConfigSample] Update versions
JolandaVerhoef Oct 26, 2021
d990d5e
[TestConfigurationSample] Upgrade to AGP alpha03
JolandaVerhoef Nov 9, 2021
728a4e5
[TestConfigurationSample] Upgrade to AGP alpha04
JolandaVerhoef Nov 10, 2021
5023df2
Revert "[ConfigSample] Use ubuntu image as hardware acceleration is n…
JolandaVerhoef Nov 10, 2021
2a4b086
[TestConfigurationSample] Provide emulator logs as artifact on failin…
JolandaVerhoef Nov 15, 2021
972c596
[TestConfigurationSample] Provide emulator logs as artifact on failin…
JolandaVerhoef Nov 15, 2021
dfb8fad
[TestConfigurationSample] Upgrade to AGP alpha06
JolandaVerhoef Dec 16, 2021
5f53fdf
[TestConfigurationSample] Upgrade to AGP alpha07
JolandaVerhoef Jan 13, 2022
9805b89
[TestConfigurationSample] Upgrade to AGP 7.3.0-alpha05
JolandaVerhoef Mar 9, 2022
339d550
[TestConfigurationSample] Upgrade to AGP 7.3.0-alpha06
JolandaVerhoef Mar 15, 2022
68819c2
[TestConfigurationSample] Upgrade to AGP 7.3.0-alpha07
JolandaVerhoef Mar 18, 2022
95c1e44
[TestConfigurationSample] Run GMD tasks with flag to disable hardware…
JolandaVerhoef Mar 18, 2022
ad8d6c7
[TestConfigurationSample] Change API26 to API27 as 26 is not supported
JolandaVerhoef Mar 18, 2022
9398a17
[TestConfigurationSample] Set max workers to 2 as per recommendation
JolandaVerhoef Mar 18, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions .github/ci-gradle.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#
# Copyright 2021 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.
#

org.gradle.daemon=false
org.gradle.parallel=true
org.gradle.jvmargs=-Xmx5120m
org.gradle.workers.max=2

kotlin.incremental=false
kotlin.compiler.execution.strategy=in-process

# Controls KotlinOptions.allWarningsAsErrors. This is used in CI and can be set in local properties.
warningsAsErrors=true
123 changes: 123 additions & 0 deletions .github/workflows/TestConfigurationSample.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
name: TestConfigurationSample

on:
push:
branches:
- main
paths:
- 'TestConfigurationSample/**'
pull_request:
paths:
- 'TestConfigurationSample/**'

env:
SAMPLE_PATH: TestConfigurationSample

jobs:
build:
runs-on: ubuntu-latest
timeout-minutes: 30

steps:
- name: Checkout
uses: actions/checkout@v2

- name: Copy CI gradle.properties
run: mkdir -p ~/.gradle ; cp .github/ci-gradle.properties ~/.gradle/gradle.properties

- name: Set up JDK 11
uses: actions/setup-java@v1
with:
java-version: 11

- name: Generate cache key
run: ./scripts/checksum.sh $SAMPLE_PATH checksum.txt

- uses: actions/cache@v2
with:
path: |
~/.gradle/caches/modules-*
~/.gradle/caches/jars-*
~/.gradle/caches/build-cache-*
key: gradle-${{ hashFiles('checksum.txt') }}

- name: Build project and run local tests
working-directory: ${{ env.SAMPLE_PATH }}
run: ./gradlew spotlessCheck assembleDebug lintDebug testDebug --stacktrace --no-build-cache --rerun-tasks

gradleManagedVirtualDevicesTest:
needs: build
runs-on: macos-latest
timeout-minutes: 30

steps:
- name: Checkout
uses: actions/checkout@v2

- name: Copy CI gradle.properties
run: mkdir -p ~/.gradle ; cp .github/ci-gradle.properties ~/.gradle/gradle.properties

- name: Set up JDK 11
uses: actions/setup-java@v1
with:
java-version: 11

- name: Generate cache key for Gradle cache
run: ./scripts/checksum.sh $SAMPLE_PATH checksum.txt

- uses: actions/cache@v2
with:
path: |
~/.gradle/caches/modules-*
~/.gradle/caches/jars-*
~/.gradle/caches/build-cache-*
key: gradle-${{ hashFiles('checksum.txt') }}

- name: Cache pixel2api30 system image
uses: actions/cache@v2
with:
path: |
~/.android/gradle/avd/dev30_aosp_x86_Pixel_2.*
~/.android/gradle/avd/dev30_aosp_x86_64_Pixel_2.*
key: pixel2api30

- name: Cache pixel2api27 system image
uses: actions/cache@v2
with:
path: ~/.android/gradle/avd/dev27_aosp_x86_Pixel_2.*
key: pixel2api27

- name: Cache nexus9api29 system image
uses: actions/cache@v2
with:
path: ~/.android/gradle/avd/dev29_aosp_x86_Nexus_9.*
key: nexus9api29

- name: Run all tests
working-directory: ${{ env.SAMPLE_PATH }}
run: ./gradlew -Dorg.gradle.workers.max=2 -i pixel2api30DebugAndroidTest -Pandroid.testInstrumentationRunnerArguments.notAnnotation=com.example.android.testing.testconfigurationsample.TestDeviceLargeScreen -Pandroid.testoptions.manageddevices.emulator.gpu="swiftshader_indirect"

- name: Run regression tests
working-directory: ${{ env.SAMPLE_PATH }}
run: ./gradlew -Dorg.gradle.workers.max=2 -i pixel2api27DebugAndroidTest -Pandroid.testInstrumentationRunnerArguments.annotation=com.example.android.testing.testconfigurationsample.TestDeviceApi27 -Pandroid.testoptions.manageddevices.emulator.gpu="swiftshader_indirect"

- name: Run large screen tests
working-directory: ${{ env.SAMPLE_PATH }}
run: ./gradlew -Dorg.gradle.workers.max=2 -i nexus9api29DebugAndroidTest -Pandroid.testInstrumentationRunnerArguments.annotation=com.example.android.testing.testconfigurationsample.TestDeviceLargeScreen -Pandroid.testoptions.manageddevices.emulator.gpu="swiftshader_indirect"

- name: Upload test reports
if: always()
uses: actions/upload-artifact@v2
with:
name: test-reports
path: ${{ env.SAMPLE_PATH }}/app/build/reports/androidTests

- name: Upload emulator logs
if: failure()
uses: actions/upload-artifact@v2
with:
name: emulator-logs
path: |
${{ env.SAMPLE_PATH }}/app/build/outputs/androidTest-results/managedDevice/**
!${{ env.SAMPLE_PATH }}/**/*:*.xml
!${{ env.SAMPLE_PATH }}/**/*|*
15 changes: 15 additions & 0 deletions TestConfigurationSample/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
*.iml
.gradle
/local.properties
/.idea/caches
/.idea/libraries
/.idea/modules.xml
/.idea/workspace.xml
/.idea/navEditor.xml
/.idea/assetWizardSettings.xml
.DS_Store
/build
/captures
.externalNativeBuild
.cxx
local.properties
30 changes: 30 additions & 0 deletions TestConfigurationSample/.google/packaging.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@

# Copyright (C) 2021 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
#
# 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.
#
# GOOGLE SAMPLE PACKAGING DATA
#
# This file is used by Google as part of our samples packaging process.
# End users may safely ignore this file. It has no relevance to other systems.
---
status: PUBLISHED
technologies: [Android]
categories: [Testing]
languages: [Kotlin]
solutions: [Mobile]
github: android/testing-samples
level: INTERMEDIATE
apiRefs:
- android:androidx.compose.Composable
license: apache2
1 change: 1 addition & 0 deletions TestConfigurationSample/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# Test Configuration Sample
1 change: 1 addition & 0 deletions TestConfigurationSample/app/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/build
83 changes: 83 additions & 0 deletions TestConfigurationSample/app/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
plugins {
id 'com.android.application'
id 'org.jetbrains.kotlin.android'
}

android {
compileSdk 31
buildToolsVersion "30.0.3"

defaultConfig {
applicationId "com.example.android.testing.testconfigurationsample"
minSdk 23
targetSdk 31
versionCode 1
versionName "1.0"

testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
vectorDrawables {
useSupportLibrary true
}
}

buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
kotlinOptions {
jvmTarget = '1.8'
}
buildFeatures {
compose true
}
composeOptions {
kotlinCompilerExtensionVersion compose_version
}
packagingOptions {
resources {
excludes += ['/META-INF/AL2.0', '/META-INF/LGPL2.1']
}
}


testOptions {
devices {
pixel2api30(com.android.build.api.dsl.ManagedVirtualDevice) {
// Use device profiles you typically see in Android Studio
device = "Pixel 2"
apiLevel = 30
// You can also specify "google" if you require Google Play Services.
systemImageSource = "aosp"
abi = "x86"
}
pixel2api27(com.android.build.api.dsl.ManagedVirtualDevice) {
device = "Pixel 2"
apiLevel = 27
systemImageSource = "aosp"
abi = "x86"
}
nexus9api29(com.android.build.api.dsl.ManagedVirtualDevice) {
device = "Nexus 9"
apiLevel = 29
systemImageSource = "aosp"
abi = "x86"
}
}
}
}

dependencies {
implementation "com.google.android.material:material:$material_version"
implementation "androidx.compose.ui:ui:$compose_version"
implementation "androidx.compose.material:material:$compose_version"
implementation "androidx.compose.ui:ui-tooling:$compose_version"
implementation "androidx.activity:activity-compose:$activity_compose_version"
androidTestImplementation "androidx.test.ext:junit:$junit_version"
androidTestImplementation "androidx.compose.ui:ui-test-junit4:$compose_version"
}
21 changes: 21 additions & 0 deletions TestConfigurationSample/app/proguard-rules.pro
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Add project specific ProGuard rules here.
# You can control the set of applied configuration files using the
# proguardFiles setting in build.gradle.
#
# For more details, see
# http://developer.android.com/guide/developing/tools/proguard.html

# 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 *;
#}

# Uncomment this to preserve the line number information for
# debugging stack traces.
#-keepattributes SourceFile,LineNumberTable

# If you keep the line number information, uncomment this to
# hide the original source file name.
#-renamesourcefileattribute SourceFile
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
/*
* Copyright 2021 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
*
* 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.
*/
package com.example.android.testing.testconfigurationsample

import androidx.compose.ui.test.junit4.createAndroidComposeRule
import androidx.test.ext.junit.runners.AndroidJUnit4
import kotlinx.coroutines.delay
import kotlinx.coroutines.runBlocking
import org.junit.Assert.assertTrue
import org.junit.Rule
import org.junit.Test
import org.junit.runner.RunWith

@RunWith(AndroidJUnit4::class)
class MainActivityTests {
@get:Rule
val composeTestRule = createAndroidComposeRule<MainActivity>()

@Test
fun sampleTest1() {
// Add instrumented tests here
runBlocking { delay(10000) }
assertTrue(true)
}

@Test
fun sampleTest2() {
// Add instrumented tests here
runBlocking { delay(10000) }
assertTrue(true)
}

@Test
fun sampleTest3() {
// Add instrumented tests here
runBlocking { delay(10000) }
assertTrue(true)
}

@Test
fun sampleTest4() {
// Add instrumented tests here
runBlocking { delay(10000) }
assertTrue(true)
}

/**
* When you find an issue with a specific device or API level,
* you can create an annotation for it and add it to your test.
* In your CI setup you can then run tests with these annotations
* on a specific Gradle Managed Virtual Device.
*
* See the Github Actions setup of this project for an example.
*/
@Test @TestDeviceApi27
fun regressionTestKnownIssueApi27() {
// Add instrumented tests here
runBlocking { delay(10000) }
assertTrue(true)
}
}
Loading