Skip to content

Commit e475169

Browse files
authored
Introduce instrumentation test (#5108)
* Add jackson dummy test and gradle configuration for instrumentation test * Add Instrumentation test Github Action job * Bump JDK used to 21 like Android Studio * Add missing dependency in common * Limit the instrumentationTest to common for now * Add test report junit action
1 parent 53a949e commit e475169

File tree

7 files changed

+199
-34
lines changed

7 files changed

+199
-34
lines changed
Lines changed: 26 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,32 @@
11
name: "Setup build environment"
22
description: "Setup the runner with all the tools we need to build our project."
33
inputs:
4-
mock-google-services:
5-
description: "Mock the google-services.json file inside the gradle modules."
6-
default: "false"
7-
required: false
4+
mock-google-services:
5+
description: "Mock the google-services.json file inside the gradle modules."
6+
default: "false"
7+
required: false
8+
cache-disabled:
9+
description: When 'true', all caching is disabled. No entries will be written to or read from the cache.
10+
required: false
11+
default: "false"
812
runs:
9-
using: "composite"
10-
steps:
11-
- name: Mock google-services.json
12-
shell: bash
13-
if: ${{ inputs.mock-google-services == 'true' }}
14-
run: |
15-
cp .github/mock-google-services.json app/google-services.json
16-
cp .github/mock-google-services.json wear/google-services.json
17-
cp .github/mock-google-services.json automotive/google-services.json
13+
using: "composite"
14+
steps:
15+
- name: Mock google-services.json
16+
shell: bash
17+
if: ${{ inputs.mock-google-services == 'true' }}
18+
run: |
19+
cp .github/mock-google-services.json app/google-services.json
20+
cp .github/mock-google-services.json wear/google-services.json
21+
cp .github/mock-google-services.json automotive/google-services.json
1822
19-
- name: Set up JDK 17
20-
uses: actions/setup-java@v4.7.0
21-
with:
22-
distribution: "temurin"
23-
java-version: "17"
23+
- name: Set up JDK 21
24+
uses: actions/setup-java@v4.7.0
25+
with:
26+
distribution: "temurin"
27+
java-version: "21"
2428

25-
- name: Setup Gradle
26-
uses: gradle/actions/setup-gradle@v4
29+
- name: Setup Gradle
30+
uses: gradle/actions/setup-gradle@v4
31+
with:
32+
cache-disabled: ${{ inputs.cache-disabled == 'true'}}

.github/workflows/pr.yml

Lines changed: 97 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,11 @@ jobs:
2323
- name: Validate ktlint
2424
run: ./gradlew ktlintCheck
2525

26-
- name: Upload lint reports (SARIF)
27-
if: ${{ !cancelled() && hashFiles('**/*.sarif') != '' }}
28-
uses: github/codeql-action/upload-sarif@v3
29-
with:
30-
sarif_file: './'
26+
- name: Upload lint reports (SARIF)
27+
if: ${{ !cancelled() && hashFiles('**/*.sarif') != '' }}
28+
uses: github/codeql-action/upload-sarif@v3
29+
with:
30+
sarif_file: "./"
3131

3232
lint:
3333
runs-on: ubuntu-latest
@@ -48,13 +48,13 @@ jobs:
4848
uses: actions/upload-artifact@v4
4949
with:
5050
name: lint-reports
51-
path: '**/build/reports/lint-results-*.html'
51+
path: "**/build/reports/lint-results-*.html"
5252

5353
- name: Upload lint reports (SARIF)
5454
if: ${{ !cancelled() && hashFiles('**/*.sarif') != '' }}
5555
uses: github/codeql-action/upload-sarif@v3
5656
with:
57-
sarif_file: './'
57+
sarif_file: "./"
5858

5959
pr_build:
6060
runs-on: ubuntu-latest
@@ -96,3 +96,93 @@ jobs:
9696
uses: actions/upload-artifact@v4
9797
with:
9898
path: ./**/*.apk
99+
100+
instrumentation_test:
101+
name: "Instrumentation Tests"
102+
runs-on: ubuntu-latest
103+
strategy:
104+
# We want the result of each device to be reported, so we can't fail-fast
105+
fail-fast: false
106+
matrix:
107+
api-level: [21, 35]
108+
steps:
109+
- name: Delete unnecessary tools 🔧
110+
uses: jlumbroso/free-disk-space@v1.3.1
111+
with:
112+
android: false # Don't remove Android tools
113+
tool-cache: true # Remove image tool cache - rm -rf "$AGENT_TOOLSDIRECTORY"
114+
docker-images: false # Takes 16s, enable if needed in the future
115+
large-packages: false # includes google-cloud-sdk and it's slow
116+
117+
- uses: actions/checkout@v4
118+
119+
- uses: ./.github/actions/setup-build-env
120+
with:
121+
mock-google-services: "true"
122+
123+
- name: Enable KVM group perms
124+
run: |
125+
echo 'KERNEL=="kvm", GROUP="kvm", MODE="0666", OPTIONS+="static_node=kvm"' | sudo tee /etc/udev/rules.d/99-kvm4all.rules
126+
sudo udevadm control --reload-rules
127+
sudo udevadm trigger --name-match=kvm
128+
ls /dev/kvm
129+
130+
- name: AVD cache
131+
uses: actions/cache@v4
132+
id: avd-cache
133+
with:
134+
path: |
135+
~/.android/avd/*
136+
~/.android/adb*
137+
key: avd-${{ matrix.api-level }}
138+
139+
- name: Create AVD and generate snapshot for caching
140+
if: steps.avd-cache.outputs.cache-hit != 'true'
141+
uses: reactivecircus/android-emulator-runner@v2
142+
with:
143+
api-level: ${{ matrix.api-level }}
144+
arch: x86_64
145+
force-avd-creation: false
146+
disable-animations: true
147+
emulator-options: -no-window -gpu swiftshader_indirect -noaudio -no-boot-anim -camera-back none
148+
script: echo "Generated AVD snapshot for caching."
149+
150+
151+
- name: Build projects and run instrumentation tests
152+
uses: reactivecircus/android-emulator-runner@v2
153+
with:
154+
api-level: ${{ matrix.api-level }}
155+
arch: x86_64
156+
force-avd-creation: false
157+
disable-animations: true
158+
emulator-options: -no-snapshot-save -no-window -gpu swiftshader_indirect -noaudio -no-boot-anim -camera-back none
159+
script: ./gradlew :common:connectedDebugAndroidTest
160+
161+
- name: Upload test results
162+
if: always()
163+
uses: actions/upload-artifact@v4
164+
with:
165+
name: Instrumentation test results (API${{ matrix.api-level }})
166+
path: |
167+
**/build/reports/*
168+
**/build/outputs/*/connected/*
169+
170+
publish_test_results:
171+
name: "Publish Tests Results"
172+
needs: instrumentation_test
173+
runs-on: ubuntu-latest
174+
permissions:
175+
checks: write
176+
pull-requests: write
177+
if: always()
178+
179+
steps:
180+
- name: Download Artifacts
181+
uses: actions/download-artifact@v4
182+
183+
- name: Publish Test Results EnricoMi
184+
uses: EnricoMi/publish-unit-test-result-action@v2
185+
if: always()
186+
with:
187+
files: |
188+
**/androidTest-results/**/TEST-*.xml

build-logic/convention/src/main/kotlin/AndroidCommonConventionPlugin.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ class AndroidCommonConventionPlugin : Plugin<Project> {
3333

3434
defaultConfig {
3535
minSdk = libs.versions.androidSdk.min.get().toInt()
36+
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
3637
}
3738

3839
buildFeatures {
@@ -57,6 +58,7 @@ class AndroidCommonConventionPlugin : Plugin<Project> {
5758
lint {
5859
abortOnError = false
5960
disable += "MissingTranslation"
61+
// This report is used by Github Actions to parse the new issues and report them into the PR.
6062
sarifReport = true
6163
}
6264
}

common/build.gradle.kts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,4 +56,6 @@ dependencies {
5656
implementation(libs.emojiJava) {
5757
exclude(group = "org.json", module = "json")
5858
}
59+
60+
androidTestImplementation(libs.bundles.androidx.test)
5961
}

0 commit comments

Comments
 (0)