Skip to content

Commit abd305e

Browse files
[ConfigSample] Initial commit
1 parent cb136a9 commit abd305e

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+1148
-0
lines changed

.github/ci-gradle.properties

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
#
2+
# Copyright 2021 The Android Open Source Project
3+
#
4+
# Licensed under the Apache License, Version 2.0 (the "License");
5+
# you may not use this file except in compliance with the License.
6+
# You may obtain a copy of the License at
7+
#
8+
# http://www.apache.org/licenses/LICENSE-2.0
9+
#
10+
# Unless required by applicable law or agreed to in writing, software
11+
# distributed under the License is distributed on an "AS IS" BASIS,
12+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
# See the License for the specific language governing permissions and
14+
# limitations under the License.
15+
#
16+
17+
org.gradle.daemon=false
18+
org.gradle.parallel=true
19+
org.gradle.jvmargs=-Xmx5120m
20+
org.gradle.workers.max=2
21+
22+
kotlin.incremental=false
23+
kotlin.compiler.execution.strategy=in-process
24+
25+
# Controls KotlinOptions.allWarningsAsErrors. This is used in CI and can be set in local properties.
26+
warningsAsErrors=true
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
name: TestConfigurationSample
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
paths:
8+
- 'TestConfigurationSample/**'
9+
pull_request:
10+
paths:
11+
- 'TestConfigurationSample/**'
12+
13+
env:
14+
SAMPLE_PATH: TestConfigurationSample
15+
16+
jobs:
17+
build:
18+
runs-on: ubuntu-latest
19+
timeout-minutes: 90
20+
21+
steps:
22+
- name: Checkout
23+
uses: actions/checkout@v2
24+
25+
- name: Copy CI gradle.properties
26+
run: mkdir -p ~/.gradle ; cp .github/ci-gradle.properties ~/.gradle/gradle.properties
27+
28+
- name: Set up JDK 11
29+
uses: actions/setup-java@v1
30+
with:
31+
java-version: 11
32+
33+
- name: Generate cache key
34+
run: ./scripts/checksum.sh $SAMPLE_PATH checksum.txt
35+
36+
- uses: actions/cache@v2
37+
with:
38+
path: |
39+
~/.gradle/caches/modules-*
40+
~/.gradle/caches/jars-*
41+
~/.gradle/caches/build-cache-*
42+
key: gradle-${{ hashFiles('checksum.txt') }}
43+
44+
- name: Build project and run local tests
45+
working-directory: ${{ env.SAMPLE_PATH }}
46+
run: ./gradlew spotlessCheck assembleDebug lintDebug testDebug --stacktrace --no-build-cache --rerun-tasks
47+
48+
gradleManagedVirtualDevicesTest:
49+
needs: build
50+
runs-on: macOS-latest # enables hardware acceleration in the virtual machine
51+
timeout-minutes: 30
52+
53+
steps:
54+
- name: Checkout
55+
uses: actions/checkout@v2
56+
57+
- name: Copy CI gradle.properties
58+
run: mkdir -p ~/.gradle ; cp .github/ci-gradle.properties ~/.gradle/gradle.properties
59+
60+
- name: Set up JDK 11
61+
uses: actions/setup-java@v1
62+
with:
63+
java-version: 11
64+
65+
- name: Generate cache key
66+
run: ./scripts/checksum.sh $SAMPLE_PATH checksum.txt
67+
68+
- uses: actions/cache@v2
69+
with:
70+
path: |
71+
~/.gradle/caches/modules-*
72+
~/.gradle/caches/jars-*
73+
~/.gradle/caches/build-cache-*
74+
key: gradle-${{ hashFiles('checksum.txt') }}
75+
76+
- name: Run instrumented tests
77+
working-directory: ${{ env.SAMPLE_PATH }}
78+
run: |
79+
./gradlew pixel2api29DebugAndroidTest -Pandroid.experimental.androidTest.useUnifiedTestPlatform=true -Pandroid.testInstrumentationRunnerArguments.notAnnotation=com.example.android.testing.testconfigurationsample.TestDeviceLargeScreen
80+
./gradlew pixel2api23DebugAndroidTest -Pandroid.experimental.androidTest.useUnifiedTestPlatform=true -Pandroid.testInstrumentationRunnerArguments.annotation=com.example.android.testing.testconfigurationsample.TestDeviceApi23
81+
./gradlew nexus9api29DebugAndroidTest -Pandroid.experimental.androidTest.useUnifiedTestPlatform=true -Pandroid.testInstrumentationRunnerArguments.annotation=com.example.android.testing.testconfigurationsample.TestDeviceLargeScreen
82+
83+
- name: Upload test reports
84+
if: always()
85+
uses: actions/upload-artifact@v2
86+
with:
87+
name: test-reports
88+
path: ${{ env.SAMPLE_PATH }}/app/build/reports/androidTests

TestConfigurationSample/.gitignore

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
*.iml
2+
.gradle
3+
/local.properties
4+
/.idea/caches
5+
/.idea/libraries
6+
/.idea/modules.xml
7+
/.idea/workspace.xml
8+
/.idea/navEditor.xml
9+
/.idea/assetWizardSettings.xml
10+
.DS_Store
11+
/build
12+
/captures
13+
.externalNativeBuild
14+
.cxx
15+
local.properties
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
2+
# Copyright (C) 2021 The Android Open Source Project
3+
#
4+
# Licensed under the Apache License, Version 2.0 (the "License");
5+
# you may not use this file except in compliance with the License.
6+
# You may obtain a copy of the License at
7+
#
8+
# https://www.apache.org/licenses/LICENSE-2.0
9+
#
10+
# Unless required by applicable law or agreed to in writing, software
11+
# distributed under the License is distributed on an "AS IS" BASIS,
12+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
# See the License for the specific language governing permissions and
14+
# limitations under the License.
15+
#
16+
# GOOGLE SAMPLE PACKAGING DATA
17+
#
18+
# This file is used by Google as part of our samples packaging process.
19+
# End users may safely ignore this file. It has no relevance to other systems.
20+
---
21+
status: PUBLISHED
22+
technologies: [Android]
23+
categories: [Testing]
24+
languages: [Kotlin]
25+
solutions: [Mobile]
26+
github: android/testing-samples
27+
level: INTERMEDIATE
28+
apiRefs:
29+
- android:androidx.compose.Composable
30+
license: apache2

TestConfigurationSample/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# Test Configuration Sample
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/build
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
import com.android.build.api.dsl.ManagedVirtualDevice
2+
3+
plugins {
4+
id 'com.android.application'
5+
id 'org.jetbrains.kotlin.android'
6+
}
7+
8+
android {
9+
compileSdk 31
10+
buildToolsVersion "30.0.3"
11+
12+
defaultConfig {
13+
applicationId "com.example.android.testing.testconfigurationsample"
14+
minSdk 23
15+
targetSdk 31
16+
versionCode 1
17+
versionName "1.0"
18+
19+
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
20+
vectorDrawables {
21+
useSupportLibrary true
22+
}
23+
}
24+
25+
buildTypes {
26+
release {
27+
minifyEnabled false
28+
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
29+
}
30+
}
31+
compileOptions {
32+
sourceCompatibility JavaVersion.VERSION_1_8
33+
targetCompatibility JavaVersion.VERSION_1_8
34+
}
35+
kotlinOptions {
36+
jvmTarget = '1.8'
37+
}
38+
buildFeatures {
39+
compose true
40+
}
41+
composeOptions {
42+
kotlinCompilerExtensionVersion compose_version
43+
}
44+
45+
packagingOptions {
46+
// Multiple dependency bring these files in. Exclude them to enable
47+
// our test APK to build (has no effect on our AARs)
48+
excludes += "/META-INF/AL2.0"
49+
excludes += "/META-INF/LGPL2.1"
50+
}
51+
52+
testOptions {
53+
devices {
54+
pixel2api29(ManagedVirtualDevice) {
55+
// Use device profiles you typically see in Android Studio
56+
device = "Pixel 2"
57+
apiLevel = 29
58+
// You can also specify "google" if you require Google Play Services.
59+
systemImageSource = "aosp"
60+
abi = "x86"
61+
}
62+
pixel2api23(ManagedVirtualDevice) {
63+
device = "Pixel 2"
64+
apiLevel = 23
65+
systemImageSource = "aosp"
66+
abi = "x86"
67+
}
68+
nexus9api29(ManagedVirtualDevice) {
69+
device = "Nexus 9"
70+
apiLevel = 29
71+
systemImageSource = "aosp"
72+
abi = "x86"
73+
}
74+
}
75+
}
76+
}
77+
78+
dependencies {
79+
implementation "com.google.android.material:material:$material_version"
80+
implementation "androidx.compose.ui:ui:$compose_version"
81+
implementation "androidx.compose.material:material:$compose_version"
82+
implementation "androidx.compose.ui:ui-tooling:$compose_version"
83+
implementation "androidx.activity:activity-compose:$activity_compose_version"
84+
androidTestImplementation "androidx.test.ext:junit:$junit_version"
85+
androidTestImplementation "androidx.compose.ui:ui-test-junit4:$compose_version"
86+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Add project specific ProGuard rules here.
2+
# You can control the set of applied configuration files using the
3+
# proguardFiles setting in build.gradle.
4+
#
5+
# For more details, see
6+
# http://developer.android.com/guide/developing/tools/proguard.html
7+
8+
# If your project uses WebView with JS, uncomment the following
9+
# and specify the fully qualified class name to the JavaScript interface
10+
# class:
11+
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
12+
# public *;
13+
#}
14+
15+
# Uncomment this to preserve the line number information for
16+
# debugging stack traces.
17+
#-keepattributes SourceFile,LineNumberTable
18+
19+
# If you keep the line number information, uncomment this to
20+
# hide the original source file name.
21+
#-renamesourcefileattribute SourceFile
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
/*
2+
* Copyright 2021 The Android Open Source Project
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package com.example.android.testing.testconfigurationsample
17+
18+
import androidx.compose.ui.test.junit4.createAndroidComposeRule
19+
import androidx.compose.ui.test.onNodeWithText
20+
import androidx.test.ext.junit.runners.AndroidJUnit4
21+
import org.junit.Rule
22+
import org.junit.Test
23+
import org.junit.runner.RunWith
24+
25+
@RunWith(AndroidJUnit4::class)
26+
class MainActivityLargeScreenTests {
27+
@get:Rule
28+
val composeTestRule = createAndroidComposeRule<MainActivity>()
29+
30+
@Test @TestDeviceLargeScreen
31+
fun testLargeScreenText() {
32+
composeTestRule.onNodeWithText("Hi Large Screen!").assertExists()
33+
}
34+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
/*
2+
* Copyright 2021 The Android Open Source Project
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package com.example.android.testing.testconfigurationsample
17+
18+
import androidx.compose.ui.test.junit4.createAndroidComposeRule
19+
import androidx.test.ext.junit.runners.AndroidJUnit4
20+
import kotlinx.coroutines.delay
21+
import kotlinx.coroutines.runBlocking
22+
import org.junit.Assert
23+
import org.junit.Assert.assertTrue
24+
import org.junit.Rule
25+
import org.junit.Test
26+
import org.junit.runner.RunWith
27+
28+
@RunWith(AndroidJUnit4::class)
29+
class MainActivityTests {
30+
@get:Rule
31+
val composeTestRule = createAndroidComposeRule<MainActivity>()
32+
33+
@Test
34+
fun sampleTest1() {
35+
// Add instrumented tests here
36+
runBlocking { delay(10000) }
37+
assertTrue(true)
38+
}
39+
40+
@Test
41+
fun sampleTest2() {
42+
// Add instrumented tests here
43+
runBlocking { delay(10000) }
44+
assertTrue(true)
45+
}
46+
47+
@Test
48+
fun sampleTest3() {
49+
// Add instrumented tests here
50+
runBlocking { delay(10000) }
51+
assertTrue(true)
52+
}
53+
54+
@Test
55+
fun sampleTest4() {
56+
// Add instrumented tests here
57+
runBlocking { delay(10000) }
58+
assertTrue(true)
59+
}
60+
61+
/**
62+
* When you find an issue with a specific device or API level,
63+
* you can create an annotation for it and add it to your test.
64+
* In your CI setup you can then run tests with these annotations
65+
* on a specific Gradle Managed Virtual Device.
66+
*
67+
* See the Github Actions setup of this project for an example.
68+
*/
69+
@Test @TestDeviceApi23
70+
fun regressionTestKnownIssueApi23() {
71+
// Add instrumented tests here
72+
runBlocking { delay(10000) }
73+
Assert.assertTrue(true)
74+
}
75+
}

0 commit comments

Comments
 (0)