Skip to content

Commit

Permalink
chore(android): add end to end tests for event collection
Browse files Browse the repository at this point in the history
  • Loading branch information
abhaysood committed Aug 16, 2024
1 parent 293336a commit f2eff6b
Show file tree
Hide file tree
Showing 11 changed files with 1,502 additions and 25 deletions.
38 changes: 32 additions & 6 deletions android/docs/internal-documentation.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
* [Exceptions and ANRs export](#exceptions-and-anrs-export)
* [Thread management](#thread-management)
* [Configuration](#configuration)
* [Testing](#testing)

# Storage

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

See [README](../../docs/android/configuration-options.md) for more details about the
available configurations.

## Applying configs

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

## Remote config
# Testing

The SDK is tested using both unit tests and integration tests. Certain unit tests which require
Android framework classes are run using Robolectric. The integration tests are run using Espresso
and UI Automator.

To run unit tests, use the following command:
```shell
./gradlew :measure:test
```

To run integration tests (requires a device), use the following command:
```shell
./gradlew :measure:connectedAndroidTest
```

The _Measure gradle plugin_ also contains both unit tests and functional tests. The functional tests
are run using the [testkit by autonomous apps](https://github.com/autonomousapps/dependency-analysis-gradle-plugin/tree/main/testkit)
and use JUnit5 for testing as it provides an easy way to run parameterized tests.

Although not implemented yet, the config is expected to be modified from the dashboard, and the
changes should be reflected in the SDK. Config received from the server is also expected to be
persisted and used for subsequent initializations. Once implemented, the config passed in during
initialization will be overridden by the config received from the server. During initialization, the
the persisted config will be used over the config passed in during initialization.
TO run the unit tests, use the following command:
```shell
./gradlew :measure-gradle-plugin:test
```

To run the functional tests, use the following command:
```shell
./gradlew :measure-gradle-plugin:functionalTest
```
4 changes: 4 additions & 0 deletions android/gradle/libs.versions.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
[versions]
agp = "8.5.1"
benchmarkJunit4 = "1.2.4"
bundletool = "1.17.0"
# android-tools is used for calculating app size and aab size by the gradle plugin.
# The version should remain compatible with lower versions of android gradle plugin. New versions
Expand Down Expand Up @@ -36,6 +37,7 @@ kotlinx-serialization-json = "1.6.2"
google-material = "1.11.0"
mockito-kotlin = "5.1.0"
nhaarman-mockito-kotlin = "2.2.0"
orchestrator = "1.5.0"
semver = "1.1.2"
squareup-curtains = "1.2.4"
squareup-okhttp = "4.12.0"
Expand All @@ -53,6 +55,7 @@ mavenPublish = "0.29.0"
androidx-activity-compose = { module = "androidx.activity:activity-compose", version.ref = "androidx-activity-compose" }
androidx-annotation = { module = "androidx.annotation:annotation", version.ref = "androidx-annotation" }
androidx-appcompat = { module = "androidx.appcompat:appcompat", version.ref = "androidx-appcompat" }
androidx-benchmark-junit4 = { module = "androidx.benchmark:benchmark-junit4", version.ref = "benchmarkJunit4" }
androidx-benchmark-macro-junit4 = { module = "androidx.benchmark:benchmark-macro-junit4", version.ref = "androidx-benchmark-macro-junit4" }
androidx-constraintlayout = { module = "androidx.constraintlayout:constraintlayout", version.ref = "androidx-constraintlayout" }
androidx-core-ktx = { module = "androidx.core:core-ktx", version.ref = "androidx-core-ktx" }
Expand All @@ -77,6 +80,7 @@ androidx-compose-ui-tooling = { module = "androidx.compose.ui:ui-tooling", versi
androidx-compose-ui-tooling-preview = { module = "androidx.compose.ui:ui-tooling-preview", version.ref = "androidx-compose-ui" }
androidx-compose-runtime-android = { module = "androidx.compose.runtime:runtime-android", version.ref = "androidx-runtime-android" }
androidx-uiautomator = { module = "androidx.test.uiautomator:uiautomator", version.ref = "androidx-uiautomator" }
androidx-orchestrator = { module = "androidx.test:orchestrator", version.ref = "orchestrator" }
agp = { module = "com.android.tools.build:gradle", version.ref = "agp" }
asm-commons = { module = "org.ow2.asm:asm-commons", version.ref = "asm-util" }
asm-util = { module = "org.ow2.asm:asm-util", version.ref = "asm-util" }
Expand Down
11 changes: 10 additions & 1 deletion android/measure/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ android {
defaultConfig {
minSdk = 21
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
testInstrumentationRunnerArguments["clearPackageData"] = "true"
consumerProguardFiles("consumer-rules.pro")
}

Expand All @@ -88,6 +89,7 @@ android {
unitTests {
isIncludeAndroidResources = true
isReturnDefaultValues = true
execution = "ANDROIDX_TEST_ORCHESTRATOR"
}
}
buildFeatures {
Expand Down Expand Up @@ -138,7 +140,10 @@ fun configureSpotlessKotlin(spotlessExtension: SpotlessExtension) {
spotlessExtension.kotlin {
ktlint().apply {
editorConfigOverride(
mapOf("max_line_length" to 2147483647),
mapOf(
"max_line_length" to 2147483647,
"ktlint_function_naming_ignore_when_annotated_with" to "Composable",
),
)
}
target("src/**/*.kt")
Expand Down Expand Up @@ -183,4 +188,8 @@ dependencies {
androidTestImplementation(libs.androidx.activity.compose)
androidTestImplementation(libs.androidx.navigation.compose)
androidTestImplementation(libs.androidx.rules)
androidTestImplementation(libs.androidx.uiautomator)
androidTestImplementation(libs.squareup.okhttp.mockwebserver)
androidTestUtil(libs.androidx.orchestrator)
androidTestImplementation(libs.androidx.benchmark.junit4)
}
23 changes: 10 additions & 13 deletions android/measure/src/androidTest/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="sh.measure.android.test">

<!--
Expand All @@ -8,21 +7,19 @@
Version 1.3.1 of the AndroidX Test libraries remove the need for this workaround.
-->
<uses-permission android:name="android.permission.QUERY_ALL_PACKAGES" />

<uses-sdk tools:overrideLibrary="android_libs.ub_uiautomator" />

<application>
<activity android:name="sh.measure.android.gestures.GestureTestActivity" />
<activity android:name="sh.measure.android.TestActivity" />

<!-- disable auto initialization of Measure for tests -->
<provider
android:name="sh.measure.android.MeasureInitProvider"
android:authorities="${applicationId}.MeasureInitProvider"
android:enabled="false"
android:exported="false" />
<activity android:name="sh.measure.android.TestActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>

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

Loading

0 comments on commit f2eff6b

Please sign in to comment.