-
Notifications
You must be signed in to change notification settings - Fork 275
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
test(android): add instrumentation test github action #4178
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,6 +3,10 @@ on: | |
workflow_call: | ||
workflow_dispatch: | ||
|
||
defaults: | ||
run: | ||
working-directory: ./kotlin/android | ||
|
||
permissions: | ||
contents: 'read' | ||
id-token: 'write' | ||
|
@@ -11,9 +15,6 @@ jobs: | |
static-analysis: | ||
# Android SDK tools hardware accel is available only on Linux runners | ||
runs-on: ubuntu-22.04 | ||
defaults: | ||
run: | ||
working-directory: ./kotlin/android | ||
steps: | ||
- uses: actions/checkout@v4 | ||
- uses: actions/setup-java@v4 | ||
|
@@ -33,9 +34,6 @@ jobs: | |
build: | ||
# Android SDK tools hardware accel is available only on Linux runners | ||
runs-on: ubuntu-22.04 | ||
defaults: | ||
run: | ||
working-directory: ./kotlin/android | ||
steps: | ||
- uses: actions/checkout@v4 | ||
- uses: ./.github/actions/setup-rust | ||
|
@@ -59,9 +57,8 @@ jobs: | |
KEYSTORE_PATH=$(pwd)/app/keystore.jks | ||
echo -n "$KEYSTORE_BASE64" | base64 --decode > $KEYSTORE_PATH | ||
./gradlew bundleRelease | ||
- name: Run Test | ||
- name: Run Unit Test | ||
run: | | ||
# TODO: See https://github.com/firezone/firezone/issues/2311 | ||
./gradlew testReleaseUnitTest | ||
- name: Upload app bundle | ||
uses: actions/upload-artifact@v4 | ||
|
@@ -78,3 +75,60 @@ jobs: | |
run: | | ||
echo -n "$FIREBASE_APP_DISTRIBUTION_CREDENTIALS" > $FIREBASE_CREDENTIALS_PATH | ||
./gradlew --info appDistributionUploadRelease uploadCrashlyticsSymbolFileRelease | ||
|
||
ui-test: | ||
name: ui-test-api-${{ matrix.api-level }} | ||
strategy: | ||
fail-fast: false | ||
matrix: | ||
include: | ||
- api-level: 26 | ||
- api-level: 29 | ||
# Android SDK tools hardware accel is available only on Linux runners | ||
runs-on: ubuntu-22.04 | ||
steps: | ||
- name: Free Disk Space (Ubuntu) | ||
uses: jlumbroso/free-disk-space@main | ||
with: | ||
tool-cache: false | ||
android: false | ||
dotnet: true | ||
haskell: true | ||
large-packages: false | ||
swap-storage: true | ||
Comment on lines
+90
to
+98
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this still needed? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, I run into issues with space on the runners |
||
- uses: actions/checkout@v4 | ||
- uses: ./.github/actions/setup-rust | ||
with: | ||
targets: armv7-linux-androideabi aarch64-linux-android x86_64-linux-android i686-linux-android | ||
- uses: actions/setup-java@v4 | ||
with: | ||
distribution: temurin | ||
java-version: 17 | ||
- name: Setup Gradle | ||
uses: gradle/actions/setup-gradle@v3 | ||
- name: AVD cache | ||
uses: actions/cache@v4 | ||
id: avd-cache | ||
with: | ||
path: | | ||
~/.android/avd/* | ||
~/.android/adb* | ||
key: avd-${{ matrix.api-level }} | ||
- name: create AVD and generate snapshot for caching | ||
if: steps.avd-cache.outputs.cache-hit != 'true' | ||
uses: reactivecircus/android-emulator-runner@v2 | ||
with: | ||
api-level: ${{ matrix.api-level }} | ||
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: Run Tests | ||
uses: reactivecircus/android-emulator-runner@v2 | ||
with: | ||
api-level: ${{ matrix.api-level }} | ||
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: ./gradlew --stacktrace connectedCheck | ||
working-directory: ./kotlin/android |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
17 changes: 17 additions & 0 deletions
17
kotlin/android/app/src/androidTest/java/dev/firezone/android/core/HiltTestRunner.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
/* Licensed under Apache 2.0 (C) 2024 Firezone, Inc. */ | ||
package dev.firezone.android.core | ||
|
||
import android.app.Application | ||
import android.content.Context | ||
import androidx.test.runner.AndroidJUnitRunner | ||
import dagger.hilt.android.testing.HiltTestApplication | ||
|
||
class HiltTestRunner : AndroidJUnitRunner() { | ||
override fun newApplication( | ||
cl: ClassLoader?, | ||
className: String?, | ||
context: Context?, | ||
): Application { | ||
return super.newApplication(cl, HiltTestApplication::class.java.name, context) | ||
} | ||
} |
56 changes: 56 additions & 0 deletions
56
kotlin/android/app/src/androidTest/java/dev/firezone/android/core/ViewActions.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
/* Licensed under Apache 2.0 (C) 2024 Firezone, Inc. */ | ||
package dev.firezone.android.core | ||
|
||
import android.view.View | ||
import androidx.test.espresso.PerformException | ||
import androidx.test.espresso.UiController | ||
import androidx.test.espresso.ViewAction | ||
import androidx.test.espresso.matcher.ViewMatchers.isRoot | ||
import androidx.test.espresso.util.HumanReadables | ||
import androidx.test.espresso.util.TreeIterables | ||
import org.hamcrest.Matcher | ||
import org.hamcrest.StringDescription | ||
import java.util.concurrent.TimeoutException | ||
import kotlin.time.Duration | ||
import kotlin.time.Duration.Companion.seconds | ||
|
||
fun waitForView( | ||
vararg matchers: Matcher<View>, | ||
timeout: Duration = 5.seconds, | ||
): ViewAction { | ||
return object : ViewAction { | ||
private val timeoutMillis = timeout.inWholeMilliseconds | ||
|
||
override fun getConstraints() = isRoot() | ||
|
||
override fun getDescription(): String { | ||
val subDescription = StringDescription() | ||
matchers.forEach { it.describeTo(subDescription) } | ||
return "Wait for a view matching one of: $subDescription; with a timeout of $timeout." | ||
} | ||
|
||
override fun perform( | ||
uiController: UiController, | ||
rootView: View, | ||
) { | ||
uiController.loopMainThreadUntilIdle() | ||
val startTime = System.currentTimeMillis() | ||
val endTime = startTime + timeoutMillis | ||
|
||
do { | ||
for (child in TreeIterables.breadthFirstViewTraversal(rootView)) { | ||
if (matchers.any { matcher -> matcher.matches(child) }) { | ||
return | ||
} | ||
} | ||
uiController.loopMainThreadForAtLeast(100) | ||
} while (System.currentTimeMillis() < endTime) | ||
|
||
throw PerformException.Builder() | ||
.withCause(TimeoutException()) | ||
.withActionDescription(this.description) | ||
.withViewDescription(HumanReadables.describe(rootView)) | ||
.build() | ||
} | ||
} | ||
} |
18 changes: 18 additions & 0 deletions
18
kotlin/android/app/src/androidTest/java/dev/firezone/android/core/di/TestRuntimeModule.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
/* Licensed under Apache 2.0 (C) 2024 Firezone, Inc. */ | ||
package dev.firezone.android.core.di | ||
|
||
import dagger.Module | ||
import dagger.Provides | ||
import dagger.hilt.components.SingletonComponent | ||
import dagger.hilt.testing.TestInstallIn | ||
import dev.firezone.android.core.ApplicationMode | ||
|
||
@Module | ||
@TestInstallIn( | ||
components = [SingletonComponent::class], | ||
replaces = [RuntimeModule::class], | ||
) | ||
object TestRuntimeModule { | ||
@Provides | ||
internal fun provideApplicationMode() = ApplicationMode.TESTING | ||
} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Calling it a
ui-test
because that has specific meaning in an android context. See: https://developer.android.com/training/testing/instrumented-tests/ui-testsOther UI tests can base it off of this :)