-
Notifications
You must be signed in to change notification settings - Fork 3.6k
Add Test Configuration Sample #400
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
Open
JolandaVerhoef
wants to merge
21
commits into
main
Choose a base branch
from
jv/gradle-managed-virtual-devices
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 5 commits
Commits
Show all changes
21 commits
Select commit
Hold shift + click to select a range
0c9fdd2
[ConfigSample] Initial commit
JolandaVerhoef 6f55b48
[ConfigSample] Add logging to gradle commands in Github Actions
JolandaVerhoef 62d4253
[ConfigSample] Upgrade Gradle plugin and remove opt-in parameter
JolandaVerhoef d20a9b7
[ConfigSample] Change API level to 26 which is supported
JolandaVerhoef b121ae5
[ConfigSample] Try out caching
JolandaVerhoef a908ff1
[ConfigSample] Use wildcard in cache path
JolandaVerhoef 1c5241b
[ConfigSample] Use ubuntu image as hardware acceleration is not needed
JolandaVerhoef 7899cc5
[ConfigSample] Update versions
JolandaVerhoef d990d5e
[TestConfigurationSample] Upgrade to AGP alpha03
JolandaVerhoef 728a4e5
[TestConfigurationSample] Upgrade to AGP alpha04
JolandaVerhoef 5023df2
Revert "[ConfigSample] Use ubuntu image as hardware acceleration is n…
JolandaVerhoef 2a4b086
[TestConfigurationSample] Provide emulator logs as artifact on failin…
JolandaVerhoef 972c596
[TestConfigurationSample] Provide emulator logs as artifact on failin…
JolandaVerhoef dfb8fad
[TestConfigurationSample] Upgrade to AGP alpha06
JolandaVerhoef 5f53fdf
[TestConfigurationSample] Upgrade to AGP alpha07
JolandaVerhoef 9805b89
[TestConfigurationSample] Upgrade to AGP 7.3.0-alpha05
JolandaVerhoef 339d550
[TestConfigurationSample] Upgrade to AGP 7.3.0-alpha06
JolandaVerhoef 68819c2
[TestConfigurationSample] Upgrade to AGP 7.3.0-alpha07
JolandaVerhoef 95c1e44
[TestConfigurationSample] Run GMD tasks with flag to disable hardware…
JolandaVerhoef ad8d6c7
[TestConfigurationSample] Change API26 to API27 as 26 is not supported
JolandaVerhoef 9398a17
[TestConfigurationSample] Set max workers to 2 as per recommendation
JolandaVerhoef 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
| 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 |
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,101 @@ | ||
| 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.ini | ||
| ~/.android/gradle/avd/dev29_aosp_x86_Pixel_2.avd | ||
| 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 | ||
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,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 |
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,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 |
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 @@ | ||
| # Test Configuration Sample |
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 @@ | ||
| /build |
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,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" | ||
| } |
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,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 |
74 changes: 74 additions & 0 deletions
74
...androidTest/java/com/example/android/testing/testconfigurationsample/MainActivityTests.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,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) | ||
| } | ||
| } |
26 changes: 26 additions & 0 deletions
26
...oidTest/java/com/example/android/testing/testconfigurationsample/TestDeviceAnnotations.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,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 |
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.
Uh oh!
There was an error while loading. Please reload this page.