Skip to content

Commit cc9aa39

Browse files
Merge pull request #3 from android/ja/tests
Adds Preview Screenshot tool and basic tests + fixes build
2 parents 3e2989f + 8b4473e commit cc9aa39

File tree

48 files changed

+755
-25
lines changed

Some content is hidden

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

48 files changed

+755
-25
lines changed

.github/ci-gradle.properties

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#
2+
# Copyright 2020 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

.github/workflows/build_and_test.yml

Lines changed: 146 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,146 @@
1+
name: Build and Test
2+
3+
on:
4+
push:
5+
branches: [ "main" ]
6+
pull_request:
7+
branches: [ "main" ]
8+
workflow_dispatch:
9+
10+
# Ensure that only the latest commit is tested for PRs
11+
concurrency:
12+
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.sha }}
13+
cancel-in-progress: true
14+
15+
permissions:
16+
contents: write # Needed for git-auto-commit-action
17+
18+
jobs:
19+
build_test_lint:
20+
name: "Build, Test, and Lint"
21+
runs-on: ubuntu-latest
22+
timeout-minutes: 60
23+
24+
steps:
25+
- name: Checkout code
26+
uses: actions/checkout@v4
27+
28+
- name: Set up JDK 17
29+
uses: actions/setup-java@v4
30+
with:
31+
java-version: '17'
32+
distribution: 'temurin'
33+
34+
- name: Setup Gradle
35+
uses: gradle/actions/setup-gradle@v4
36+
# Add cache-encryption-key if you set up the GRADLE_ENCRYPTION_KEY secret
37+
# with:
38+
# cache-encryption-key: ${{ secrets.GRADLE_ENCRYPTION_KEY }}
39+
40+
- name: Grant execute permission for gradlew
41+
run: chmod +x gradlew
42+
43+
- name: Build debug APK
44+
run: ./gradlew assembleDebug --no-configuration-cache
45+
46+
- name: Apply Spotless
47+
run: ./gradlew spotlessApply --init-script gradle/init.gradle.kts --no-configuration-cache
48+
49+
- name: Commit Spotless changes
50+
uses: stefanzweifel/git-auto-commit-action@v5
51+
with:
52+
commit_message: 🤖 Apply Spotless formatting
53+
file_pattern: '**/*.kt **/*.kts **/*.java **/*.xml'
54+
55+
- name: Verify Screenshot Tests (AndroidX)
56+
run: ./gradlew validateDebugScreenshotTest
57+
58+
- name: Run local unit tests
59+
run: ./gradlew testDebugUnitTest
60+
61+
- name: Check lint
62+
run: ./gradlew lintDebug
63+
64+
- name: Upload build outputs (APKs)
65+
if: ${{ !cancelled() }}
66+
uses: actions/upload-artifact@v4
67+
with:
68+
name: APKs
69+
path: '**/build/outputs/apk/debug/*.apk'
70+
71+
- name: Upload JVM local test results (XML)
72+
if: ${{ !cancelled() }}
73+
uses: actions/upload-artifact@v4
74+
with:
75+
name: local-test-results
76+
path: '**/build/test-results/test*UnitTest/TEST-*.xml'
77+
78+
- name: Upload lint reports (HTML)
79+
if: ${{ !cancelled() }}
80+
uses: actions/upload-artifact@v4
81+
with:
82+
name: lint-reports-html
83+
path: '**/build/reports/lint-results-debug.html'
84+
85+
androidTest:
86+
name: "Instrumentation Tests (emulator)"
87+
runs-on: ubuntu-latest
88+
timeout-minutes: 60
89+
strategy:
90+
matrix:
91+
api-level: [26]
92+
93+
steps:
94+
- name: Delete unnecessary tools 🔧
95+
uses: jlumbroso/[email protected]
96+
with:
97+
android: false # Don't remove Android tools
98+
tool-cache: true # Remove image tool cache
99+
dotnet: true
100+
haskell: true
101+
swap-storage: true
102+
103+
- name: Enable KVM group perms
104+
run: |
105+
echo 'KERNEL=="kvm", GROUP="kvm", MODE="0666", OPTIONS+="static_node=kvm"' | sudo tee /etc/udev/rules.d/99-kvm4all.rules
106+
sudo udevadm control --reload-rules
107+
sudo udevadm trigger --name-match=kvm
108+
109+
- name: Checkout code
110+
uses: actions/checkout@v4
111+
112+
- name: Copy CI gradle.properties
113+
run: mkdir -p ~/.gradle ; cp .github/ci-gradle.properties ~/.gradle/gradle.properties
114+
115+
- name: Set up JDK 17
116+
uses: actions/setup-java@v4
117+
with:
118+
java-version: '17'
119+
distribution: 'temurin'
120+
121+
- name: Setup Gradle
122+
uses: gradle/actions/setup-gradle@v4
123+
124+
- name: Grant execute permission for gradlew
125+
run: chmod +x gradlew
126+
127+
- name: Build
128+
run: ./gradlew assembleDebug assembleDebugAndroidTest
129+
130+
- name: Build projects and run instrumentation tests
131+
uses: reactivecircus/android-emulator-runner@v2
132+
with:
133+
api-level: ${{ matrix.api-level }}
134+
arch: x86
135+
disable-animations: true
136+
disk-size: 6000M
137+
heap-size: 600M
138+
script: ./gradlew connectedDebugAndroidTest
139+
140+
141+
- name: Upload test reports
142+
if: ${{ !cancelled() }}
143+
uses: actions/upload-artifact@v4
144+
with:
145+
name: test-reports-${{ matrix.api-level }}
146+
path: '**/build/reports/androidTests'

app/build.gradle.kts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,4 +153,4 @@ androidComponents {
153153
beforeVariants { variantBuilder ->
154154
variantBuilder.enableAndroidTest = false
155155
}
156-
}
156+
}

app/src/main/AndroidManifest.xml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
<?xml version="1.0" encoding="utf-8"?><!--
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<!--
23
Copyright 2025 The Android Open Source Project
34
45
Licensed under the Apache License, Version 2.0 (the "License");

core/network/build.gradle.kts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,13 @@ android {
5050
}
5151
}
5252

53+
// Explicitly disable the connectedAndroidTest task for this module
54+
androidComponents {
55+
beforeVariants(selector().all()) { variant ->
56+
variant.enableAndroidTest = false
57+
}
58+
}
59+
5360
dependencies {
5461
implementation(libs.androidx.app.startup)
5562
implementation(libs.kotlinx.serialization.json)

core/network/src/main/AndroidManifest.xml

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,19 @@
1717
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
1818
xmlns:tools="http://schemas.android.com/tools">
1919
<application>
20-
20+
<provider
21+
android:name="androidx.startup.InitializationProvider"
22+
android:authorities="${applicationId}.androidx-startup"
23+
android:exported="false"
24+
tools:node="merge">
25+
<!-- Core Firebase App Initialization -->
26+
<meta-data android:name="com.android.developers.androidify.startup.FirebaseAppInitializer"
27+
android:value="androidx.startup" />
28+
<!-- Other Firebase Initializers -->
29+
<meta-data android:name="com.android.developers.androidify.startup.FirebaseAppCheckInitializer"
30+
android:value="androidx.startup" />
31+
<meta-data android:name="com.android.developers.androidify.startup.FirebaseRemoteConfigInitializer"
32+
android:value="androidx.startup" />
33+
</provider>
2134
</application>
22-
</manifest>
35+
</manifest>
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<!--
3+
Copyright 2025 The Android Open Source Project
4+
5+
Licensed under the Apache License, Version 2.0 (the "License");
6+
you may not use this file except in compliance with the License.
7+
You may obtain a copy of the License at
8+
9+
https://www.apache.org/licenses/LICENSE-2.0
10+
11+
Unless required by applicable law or agreed to in writing, software
12+
distributed under the License is distributed on an "AS IS" BASIS,
13+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
See the License for the specific language governing permissions and
15+
limitations under the License.
16+
-->
17+
<resources xmlns:android="http://schemas.android.com/apk/res/android">
18+
<initializer
19+
android:name="com.android.developers.androidify.startup.FirebaseAppCheckInitializer" />
20+
<initializer
21+
android:name="com.android.developers.androidify.startup.FirebaseRemoteConfigInitializer" />
22+
</resources>

core/testing/build.gradle.kts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,13 @@ android {
3939
}
4040
}
4141

42+
// Explicitly disable the connectedAndroidTest task for this module
43+
androidComponents {
44+
beforeVariants(selector().all()) { variant ->
45+
variant.enableAndroidTest = false
46+
}
47+
}
48+
4249
dependencies {
4350
api(libs.kotlinx.coroutines.test)
4451
implementation(platform(libs.androidx.compose.bom))

core/util/build.gradle.kts

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ android {
2727

2828
defaultConfig {
2929
minSdk = libs.versions.minSdk.get().toInt()
30-
testInstrumentationRunner = "com.android.developers.testing.AndroidifyTestRunner"
3130
}
3231

3332
compileOptions {
@@ -38,6 +37,12 @@ android {
3837
jvmTarget = libs.versions.jvmTarget.get()
3938
}
4039
}
40+
// Explicitly disable the connectedAndroidTest task for this module
41+
androidComponents {
42+
beforeVariants(selector().all()) { variant ->
43+
variant.enableAndroidTest = false
44+
}
45+
}
4146

4247
dependencies {
4348
implementation(platform(libs.androidx.compose.bom))
@@ -51,12 +56,6 @@ dependencies {
5156
implementation(libs.androidx.window.core)
5257
ksp(libs.hilt.compiler)
5358

54-
androidTestImplementation(platform(libs.androidx.compose.bom))
55-
androidTestImplementation(libs.androidx.ui.test.junit4)
56-
androidTestImplementation(libs.hilt.android.testing)
57-
androidTestImplementation(project(":core:testing")) // Add dependency
58-
kspAndroidTest(libs.hilt.compiler)
59-
6059
// debugImplementation(libs.androidx.ui.tooling)
6160
// debugImplementation(libs.androidx.ui.test.manifest)
6261
}

data/build.gradle.kts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ android {
2727

2828
defaultConfig {
2929
minSdk = libs.versions.minSdk.get().toInt()
30-
testInstrumentationRunner = "com.android.developers.testing.AndroidifyTestRunner"
3130
}
3231

3332
compileOptions {
@@ -38,6 +37,12 @@ android {
3837
jvmTarget = libs.versions.jvmTarget.get()
3938
}
4039
}
40+
// Explicitly disable the connectedAndroidTest task for this module
41+
androidComponents {
42+
beforeVariants(selector().all()) { variant ->
43+
variant.enableAndroidTest = false
44+
}
45+
}
4146

4247
dependencies {
4348
implementation(project(":core:network"))
@@ -55,9 +60,4 @@ dependencies {
5560
exclude(group = "com.google.guava")
5661
}
5762
ksp(libs.hilt.compiler)
58-
59-
androidTestImplementation(libs.androidx.ui.test.junit4)
60-
androidTestImplementation(libs.hilt.android.testing)
61-
androidTestImplementation(project(":core:testing"))
62-
kspAndroidTest(libs.hilt.compiler)
6363
}

0 commit comments

Comments
 (0)