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

Improved speed of instrumentation tests on CI #581

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
80 changes: 43 additions & 37 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -102,56 +102,62 @@ jobs:
- uses: gradle/gradle-build-action@v2
with:
cache-read-only: ${{ env.MAIN_BRANCH != 'true' }}
- name: Pre build sources before launching emulator
run: ./gradlew compileDebugAndroidTestSources
- name: AVD cache
uses: actions/cache@v3
id: avd-cache
with:
path: |
~/.android/avd/*
~/.android/adb*
key: avd-29
- name: Create AVD and generate snapshot for caching
if: steps.avd-cache.outputs.cache-hit != 'true'
uses: reactivecircus/android-emulator-runner@v2
with:
# Use API 29 https://github.com/ReactiveCircus/android-emulator-runner/issues/222
api-level: 29
arch: x86_64
force-avd-creation: false
emulator-options: -no-window -gpu swiftshader_indirect -noaudio -no-boot-anim -camera-back none
disable-animations: false
script: echo "Generated AVD snapshot for caching."
- name: Setup Android SDK
uses: android-actions/setup-android@v2
- name: Package Debug Android Test
# Flags from https://github.com/android/nowinandroid/blob/main/.github/workflows/Build.yaml
run: ./gradlew packageDebugAndroidTest
- name: Instrumentation tests
uses: reactivecircus/android-emulator-runner@v2
with:
# Use API 29 https://github.com/ReactiveCircus/android-emulator-runner/issues/222
api-level: 29
arch: x86_64
force-avd-creation: false
emulator-options: -no-snapshot-save -no-window -gpu swiftshader_indirect -noaudio -no-boot-anim -camera-back none
disable-animations: true
script: |
adb logcat > logcat.out &
./gradlew connectedCheck
- name: Managed device clean-up
# Flags from https://github.com/android/nowinandroid/blob/main/.github/workflows/Build.yaml
run: >
./gradlew cleanManagedDevices --unused-only
adb logcat > logcat.out &
./gradlew cleanManagedDevices --unused-only &&
./gradlew uiTestsDeviceDebugAndroidTest
-Dorg.gradle.workers.max=1
-Pandroid.testoptions.manageddevices.emulator.gpu="swiftshader_indirect"
-Pandroid.experimental.testOptions.managedDevices.emulator.showKernelLogging=true
- name: Upload failed instrumentation artifacts
if: failure()
uses: actions/upload-artifact@v2
with:
name: instrumentation-failures
path: |
**/build/reports
logcat.out

screenshot-tests:
name: Screenshot tests
runs-on: macOS-latest
timeout-minutes: 60
steps:
- uses: actions/checkout@v3
- uses: actions/setup-java@v3
with:
distribution: 'zulu'
java-version: '17'
- uses: gradle/wrapper-validation-action@v1
- uses: gradle/gradle-build-action@v2
with:
cache-read-only: ${{ env.MAIN_BRANCH != 'true' }}
- name: Setup Android SDK
uses: android-actions/setup-android@v2
- name: Screenshot tests
# Flags from https://github.com/android/nowinandroid/blob/main/.github/workflows/AndroidCIWithGmd.yaml
# Flags from https://github.com/android/nowinandroid/blob/main/.github/workflows/Build.yaml
run: >
adb logcat > logcat.out &
./gradlew cleanManagedDevices --unused-only &&
./gradlew screenshotTestsCompareBaseline
-Dorg.gradle.workers.max=1
-Pandroid.testoptions.manageddevices.emulator.gpu="swiftshader_indirect"
-Pandroid.experimental.testOptions.managedDevices.emulator.showKernelLogging=true
- name: Upload failed instrumentation artifacts
- name: Upload failed screenshot artifacts
if: failure()
uses: actions/upload-artifact@v2
with:
name: instrumentation-failures
name: screenshot-failures
path: |
**/build/reports
**/build/outputs/managed_device_android_test_additional_output
logcat.out

check-documentation:
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 2 additions & 0 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ androidx-test-espresso-core = "androidx.test.espresso:espresso-core:3.5.1"
androidx-test-junit = "androidx.test.ext:junit:1.1.3"
androidx-test-rules = "androidx.test:rules:1.5.0"
androidx-test-core = "androidx.test:core:1.5.0"
androidx-test-runner = "androidx.test:runner:1.5.0"
androidx-test-orchestrator = "androidx.test:orchestrator:1.4.2"
androidx-test-utils = "androidx.test.services:test-services:1.4.2"
coil-compose = { module = "io.coil-kt:coil-compose", version.ref = "coil" }
compose-bom = { group = "androidx.compose", name = "compose-bom", version.ref = "composeBom" }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,15 @@ package com.bumble.appyx.android

import com.android.build.api.dsl.CommonExtension
import com.android.build.api.dsl.DefaultConfig
import com.android.build.api.dsl.ManagedVirtualDevice
import com.android.build.api.variant.AndroidComponentsExtension
import com.bumble.appyx.versionCatalog
import org.gradle.api.JavaVersion
import org.gradle.api.Project
import org.gradle.api.artifacts.VersionCatalog
import org.gradle.api.artifacts.VersionCatalogsExtension
import org.gradle.kotlin.dsl.getByType
import org.gradle.kotlin.dsl.register

internal inline fun <
reified ConfigT : DefaultConfig,
Expand All @@ -30,6 +32,8 @@ internal inline fun <

dependencies.add("testImplementation", libs.findLibrary("junit-api").get())
dependencies.add("testRuntimeOnly", libs.findLibrary("junit-engine").get())
dependencies.add("androidTestImplementation", libs.findLibrary("androidx-test-runner").get())
dependencies.add("androidTestUtil", libs.findLibrary("androidx-test-orchestrator").get())

extensions
.getByType<ComponentsExtensionT>()
Expand Down Expand Up @@ -60,6 +64,7 @@ private fun <DefaultConfigT : DefaultConfig> CommonExtension<*, *, DefaultConfig
useSupportLibrary = true
}
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
testInstrumentationRunnerArguments["clearPackageData"] = "true"
}

val composeEnabled = appyxExtension.buildFeatures.compose.get()
Expand All @@ -77,6 +82,13 @@ private fun <DefaultConfigT : DefaultConfig> CommonExtension<*, *, DefaultConfig
unitTests.all {
it.useJUnitPlatform()
}
execution = "ANDROIDX_TEST_ORCHESTRATOR"
managedDevices.devices.register<ManagedVirtualDevice>("uiTestsDevice") {
device = "Pixel"
@Suppress("MagicNumber")
apiLevel = 30
systemImageSource = "aosp-atd"
}
}

packagingOptions {
Expand Down
14 changes: 3 additions & 11 deletions plugins/screenshot-tests/src/main/kotlin/ScreenshotTestPlugin.kt
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
import com.android.build.api.dsl.CommonExtension
import com.android.build.api.dsl.ManagedVirtualDevice
import org.gradle.api.Plugin
import org.gradle.api.Project
import org.gradle.api.artifacts.VersionCatalogsExtension
import org.gradle.kotlin.dsl.register

class ScreenshotTestPlugin : Plugin<Project> {

Expand All @@ -12,12 +10,6 @@ class ScreenshotTestPlugin : Plugin<Project> {
defaultConfig {
testInstrumentationRunnerArguments["useTestStorageService"] = "true"
}
testOptions.managedDevices.devices.register<ManagedVirtualDevice>(DEVICE_NAME) {
device = "Pixel"
@Suppress("MagicNumber")
apiLevel = 30
systemImageSource = "aosp"
}
}

target.dependencies.add(
Expand All @@ -27,14 +19,14 @@ class ScreenshotTestPlugin : Plugin<Project> {
)

target.tasks.register(TASK_RECORD, RecordScreenshotsTask::class.java) {
dependsOn(project.tasks.named("${DEVICE_NAME}Check"))
dependsOn(project.tasks.named("${DEVICE_NAME}DebugAndroidTest"))
testResultsFolder.set(
project.file("build/outputs/managed_device_android_test_additional_output/debug/$DEVICE_NAME")
)
}

target.tasks.register(TASK_COMPARE, CompareScreenshotsTask::class.java) {
dependsOn(project.tasks.named("${DEVICE_NAME}Check"))
dependsOn(project.tasks.named("${DEVICE_NAME}DebugAndroidTest"))
testResultsFolder.set(
project.file("build/outputs/managed_device_android_test_additional_output/debug/$DEVICE_NAME")
)
Expand All @@ -43,7 +35,7 @@ class ScreenshotTestPlugin : Plugin<Project> {
}

companion object {
const val DEVICE_NAME = "screenshotTestsDevice"
const val DEVICE_NAME = "uiTestsDevice"
const val GROUP = "screenshot-tests"
const val TASK_COMPARE = "screenshotTestsCompareBaseline"
const val TASK_RECORD = "screenshotTestsRecordBaseline"
Expand Down