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 6 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
99 changes: 99 additions & 0 deletions .github/workflows/TestConfigurationSample.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
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 pixel2api29 system image
uses: actions/cache@v2
with:
path: ~/.android/gradle/avd/dev29_aosp_x86_Pixel_2.*
key: pixel2api29

- name: Run all tests
working-directory: ${{ env.SAMPLE_PATH }}
run: ./gradlew pixel2api29DebugAndroidTest

# - name: Run regression tests
# working-directory: ${{ env.SAMPLE_PATH }}
# run: ./gradlew -i pixel2api26DebugAndroidTest -Pandroid.testInstrumentationRunnerArguments.annotation=com.example.android.testing.testconfigurationsample.TestDeviceApi26
#
# - name: Run large screen tests
# working-directory: ${{ env.SAMPLE_PATH }}
# run: ./gradlew -i nexus9api29DebugAndroidTest -Pandroid.testInstrumentationRunnerArguments.annotation=com.example.android.testing.testconfigurationsample.TestDeviceLargeScreen

- name: Upload test reports
if: always()
uses: actions/upload-artifact@v2
with:
name: test-reports
path: ${{ env.SAMPLE_PATH }}/app/build/reports/androidTests
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
85 changes: 85 additions & 0 deletions TestConfigurationSample/app/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
import com.android.build.api.dsl.ManagedVirtualDevice

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 {
pixel2api29(ManagedVirtualDevice) {
// Use device profiles you typically see in Android Studio
device = "Pixel 2"
apiLevel = 29
// You can also specify "google" if you require Google Play Services.
systemImageSource = "aosp"
abi = "x86"
}
pixel2api26(ManagedVirtualDevice) {
device = "Pixel 2"
apiLevel = 26
systemImageSource = "aosp"
abi = "x86"
}
nexus9api29(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 @TestDeviceApi26
fun regressionTestKnownIssueApi26() {
// Add instrumented tests here
runBlocking { delay(10000) }
assertTrue(true)
}
}
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
*
* 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

/**
* Annotate tests with this annotation when testing API 26 regression bugs.
*/
annotation class TestDeviceApi26

/**
* Annotate tests with this annotation when testing large-screen specific features.
*/
annotation class TestDeviceLargeScreen
Loading