-
Notifications
You must be signed in to change notification settings - Fork 3.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
cb136a9
commit c4a1492
Showing
41 changed files
with
1,156 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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 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,96 @@ | ||
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 # enables hardware acceleration in the virtual machine | ||
timeout-minutes: 90 | ||
|
||
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: AVD cache | ||
uses: actions/cache@v2 | ||
id: avd-cache | ||
with: | ||
path: | | ||
~/.android/gradle/avd/* | ||
key: avd | ||
|
||
- name: Run instrumented tests | ||
working-directory: ${{ env.SAMPLE_PATH }} | ||
run: | | ||
./gradlew pixel2api29DebugAndroidTest -Pandroid.experimental.androidTest.useUnifiedTestPlatform=true -Pandroid.testInstrumentationRunnerArguments.notAnnotation=com.example.android.testing.testconfigurationsample.TestDeviceLargeScreen | ||
./gradlew pixel2api23DebugAndroidTest -Pandroid.experimental.androidTest.useUnifiedTestPlatform=true -Pandroid.testInstrumentationRunnerArguments.annotation=com.example.android.testing.testconfigurationsample.TestDeviceApi23 | ||
./gradlew nexus9api29DebugAndroidTest -Pandroid.experimental.androidTest.useUnifiedTestPlatform=true -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 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 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 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 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 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,86 @@ | ||
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 { | ||
// Multiple dependency bring these files in. Exclude them to enable | ||
// our test APK to build (has no effect on our AARs) | ||
excludes += "/META-INF/AL2.0" | ||
excludes += "/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" | ||
} | ||
pixel2api23(ManagedVirtualDevice) { | ||
device = "Pixel 2" | ||
apiLevel = 23 | ||
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 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 |
34 changes: 34 additions & 0 deletions
34
.../java/com/example/android/testing/testconfigurationsample/MainActivityLargeScreenTests.kt
This file contains 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,34 @@ | ||
/* | ||
* 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.compose.ui.test.onNodeWithText | ||
import androidx.test.ext.junit.runners.AndroidJUnit4 | ||
import org.junit.Rule | ||
import org.junit.Test | ||
import org.junit.runner.RunWith | ||
|
||
@RunWith(AndroidJUnit4::class) | ||
class MainActivityLargeScreenTests { | ||
@get:Rule | ||
val composeTestRule = createAndroidComposeRule<MainActivity>() | ||
|
||
@Test @TestDeviceLargeScreen | ||
fun testLargeScreenText() { | ||
composeTestRule.onNodeWithText("Hi Large Screen!").assertExists() | ||
} | ||
} |
75 changes: 75 additions & 0 deletions
75
...androidTest/java/com/example/android/testing/testconfigurationsample/MainActivityTests.kt
This file contains 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,75 @@ | ||
/* | ||
* 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 | ||
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 @TestDeviceApi23 | ||
fun regressionTestKnownIssueApi23() { | ||
// Add instrumented tests here | ||
runBlocking { delay(10000) } | ||
Assert.assertTrue(true) | ||
} | ||
} |
Oops, something went wrong.