Skip to content

Commit f2eff6b

Browse files
committed
chore(android): add end to end tests for event collection
1 parent 293336a commit f2eff6b

File tree

11 files changed

+1502
-25
lines changed

11 files changed

+1502
-25
lines changed

android/docs/internal-documentation.md

Lines changed: 32 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
* [Exceptions and ANRs export](#exceptions-and-anrs-export)
77
* [Thread management](#thread-management)
88
* [Configuration](#configuration)
9+
* [Testing](#testing)
910

1011
# Storage
1112

@@ -118,6 +119,9 @@ sensitive information from being sent or modifying the behavior of the SDK.
118119
Any configuration change made to `MeasureConfig` is a public API change and must also result in
119120
updating the documentation.
120121

122+
See [README](../../docs/android/configuration-options.md) for more details about the
123+
available configurations.
124+
121125
## Applying configs
122126

123127
Configs which modify events, like removing fields or decision to drop events are all centralized in
@@ -129,10 +133,32 @@ changes
129133
the color of the mask applied to the screenshot. These configs are applied at the time of collection
130134
itself.
131135

132-
## Remote config
136+
# Testing
137+
138+
The SDK is tested using both unit tests and integration tests. Certain unit tests which require
139+
Android framework classes are run using Robolectric. The integration tests are run using Espresso
140+
and UI Automator.
141+
142+
To run unit tests, use the following command:
143+
```shell
144+
./gradlew :measure:test
145+
```
146+
147+
To run integration tests (requires a device), use the following command:
148+
```shell
149+
./gradlew :measure:connectedAndroidTest
150+
```
151+
152+
The _Measure gradle plugin_ also contains both unit tests and functional tests. The functional tests
153+
are run using the [testkit by autonomous apps](https://github.com/autonomousapps/dependency-analysis-gradle-plugin/tree/main/testkit)
154+
and use JUnit5 for testing as it provides an easy way to run parameterized tests.
133155

134-
Although not implemented yet, the config is expected to be modified from the dashboard, and the
135-
changes should be reflected in the SDK. Config received from the server is also expected to be
136-
persisted and used for subsequent initializations. Once implemented, the config passed in during
137-
initialization will be overridden by the config received from the server. During initialization, the
138-
the persisted config will be used over the config passed in during initialization.
156+
TO run the unit tests, use the following command:
157+
```shell
158+
./gradlew :measure-gradle-plugin:test
159+
```
160+
161+
To run the functional tests, use the following command:
162+
```shell
163+
./gradlew :measure-gradle-plugin:functionalTest
164+
```

android/gradle/libs.versions.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
[versions]
22
agp = "8.5.1"
3+
benchmarkJunit4 = "1.2.4"
34
bundletool = "1.17.0"
45
# android-tools is used for calculating app size and aab size by the gradle plugin.
56
# The version should remain compatible with lower versions of android gradle plugin. New versions
@@ -36,6 +37,7 @@ kotlinx-serialization-json = "1.6.2"
3637
google-material = "1.11.0"
3738
mockito-kotlin = "5.1.0"
3839
nhaarman-mockito-kotlin = "2.2.0"
40+
orchestrator = "1.5.0"
3941
semver = "1.1.2"
4042
squareup-curtains = "1.2.4"
4143
squareup-okhttp = "4.12.0"
@@ -53,6 +55,7 @@ mavenPublish = "0.29.0"
5355
androidx-activity-compose = { module = "androidx.activity:activity-compose", version.ref = "androidx-activity-compose" }
5456
androidx-annotation = { module = "androidx.annotation:annotation", version.ref = "androidx-annotation" }
5557
androidx-appcompat = { module = "androidx.appcompat:appcompat", version.ref = "androidx-appcompat" }
58+
androidx-benchmark-junit4 = { module = "androidx.benchmark:benchmark-junit4", version.ref = "benchmarkJunit4" }
5659
androidx-benchmark-macro-junit4 = { module = "androidx.benchmark:benchmark-macro-junit4", version.ref = "androidx-benchmark-macro-junit4" }
5760
androidx-constraintlayout = { module = "androidx.constraintlayout:constraintlayout", version.ref = "androidx-constraintlayout" }
5861
androidx-core-ktx = { module = "androidx.core:core-ktx", version.ref = "androidx-core-ktx" }
@@ -77,6 +80,7 @@ androidx-compose-ui-tooling = { module = "androidx.compose.ui:ui-tooling", versi
7780
androidx-compose-ui-tooling-preview = { module = "androidx.compose.ui:ui-tooling-preview", version.ref = "androidx-compose-ui" }
7881
androidx-compose-runtime-android = { module = "androidx.compose.runtime:runtime-android", version.ref = "androidx-runtime-android" }
7982
androidx-uiautomator = { module = "androidx.test.uiautomator:uiautomator", version.ref = "androidx-uiautomator" }
83+
androidx-orchestrator = { module = "androidx.test:orchestrator", version.ref = "orchestrator" }
8084
agp = { module = "com.android.tools.build:gradle", version.ref = "agp" }
8185
asm-commons = { module = "org.ow2.asm:asm-commons", version.ref = "asm-util" }
8286
asm-util = { module = "org.ow2.asm:asm-util", version.ref = "asm-util" }

android/measure/build.gradle.kts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ android {
6262
defaultConfig {
6363
minSdk = 21
6464
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
65+
testInstrumentationRunnerArguments["clearPackageData"] = "true"
6566
consumerProguardFiles("consumer-rules.pro")
6667
}
6768

@@ -88,6 +89,7 @@ android {
8889
unitTests {
8990
isIncludeAndroidResources = true
9091
isReturnDefaultValues = true
92+
execution = "ANDROIDX_TEST_ORCHESTRATOR"
9193
}
9294
}
9395
buildFeatures {
@@ -138,7 +140,10 @@ fun configureSpotlessKotlin(spotlessExtension: SpotlessExtension) {
138140
spotlessExtension.kotlin {
139141
ktlint().apply {
140142
editorConfigOverride(
141-
mapOf("max_line_length" to 2147483647),
143+
mapOf(
144+
"max_line_length" to 2147483647,
145+
"ktlint_function_naming_ignore_when_annotated_with" to "Composable",
146+
),
142147
)
143148
}
144149
target("src/**/*.kt")
@@ -183,4 +188,8 @@ dependencies {
183188
androidTestImplementation(libs.androidx.activity.compose)
184189
androidTestImplementation(libs.androidx.navigation.compose)
185190
androidTestImplementation(libs.androidx.rules)
191+
androidTestImplementation(libs.androidx.uiautomator)
192+
androidTestImplementation(libs.squareup.okhttp.mockwebserver)
193+
androidTestUtil(libs.androidx.orchestrator)
194+
androidTestImplementation(libs.androidx.benchmark.junit4)
186195
}
Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
2-
xmlns:tools="http://schemas.android.com/tools"
32
package="sh.measure.android.test">
43

54
<!--
@@ -8,21 +7,19 @@
87
Version 1.3.1 of the AndroidX Test libraries remove the need for this workaround.
98
-->
109
<uses-permission android:name="android.permission.QUERY_ALL_PACKAGES" />
11-
12-
<uses-sdk tools:overrideLibrary="android_libs.ub_uiautomator" />
13-
1410
<application>
15-
<activity android:name="sh.measure.android.gestures.GestureTestActivity" />
16-
<activity android:name="sh.measure.android.TestActivity" />
17-
18-
<!-- disable auto initialization of Measure for tests -->
19-
<provider
20-
android:name="sh.measure.android.MeasureInitProvider"
21-
android:authorities="${applicationId}.MeasureInitProvider"
22-
android:enabled="false"
23-
android:exported="false" />
11+
<activity android:name="sh.measure.android.TestActivity">
12+
<intent-filter>
13+
<action android:name="android.intent.action.MAIN" />
14+
<category android:name="android.intent.category.LAUNCHER" />
15+
</intent-filter>
16+
</activity>
2417

2518
<meta-data android:name="sh.measure.android.API_KEY" android:value="YOUR_API_KEY" />
19+
<!--
20+
The API_URL is used by mock web server, changing this could lead to test failures.
21+
-->
22+
<meta-data android:name="sh.measure.android.API_URL" android:value="http://localhost:8080" />
2623
</application>
2724
</manifest>
2825

0 commit comments

Comments
 (0)