diff --git a/open_wearable/.gitignore b/open_wearable/.gitignore index b223fb72a..8f0304540 100644 --- a/open_wearable/.gitignore +++ b/open_wearable/.gitignore @@ -33,6 +33,11 @@ migrate_working_dir/ .pub/ /build/ +# Patrol-generated entry point, local test settings, and run artifacts. +**/test_bundle.dart +.patrol.env +/test-results/ + # Generated plugin registrants **/GeneratedPluginRegistrant.swift **/generated_plugin_registrant.cc diff --git a/open_wearable/android/app/build.gradle b/open_wearable/android/app/build.gradle index 30ee3d7cb..8bd257b88 100644 --- a/open_wearable/android/app/build.gradle +++ b/open_wearable/android/app/build.gradle @@ -29,9 +29,17 @@ android { targetSdk = flutter.targetSdkVersion versionCode = customVersionCode.toInteger() versionName = flutter.versionName + testInstrumentationRunner "pl.leancode.patrol.PatrolJUnitRunner" + testInstrumentationRunnerArguments["clearPackageData"] = "true" } buildTypes { + debug { + // Patrol runs debug builds. Give that build its own Android identity + // so it can live beside the user's normal OpenWearables app and so + // test-data cleanup never touches the production installation. + applicationIdSuffix = ".patrol" + } release { // TODO: Add your own signing config for the release build. // Signing with the debug keys for now, so `flutter run --release` works. @@ -41,6 +49,10 @@ android { proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' } } + + testOptions { + execution "ANDROIDX_TEST_ORCHESTRATOR" + } } flutter { @@ -52,3 +64,7 @@ kotlin { jvmTarget = org.jetbrains.kotlin.gradle.dsl.JvmTarget.JVM_17 } } + +dependencies { + androidTestUtil "androidx.test:orchestrator:1.5.1" +} diff --git a/open_wearable/android/app/src/androidTest/java/edu/kit/teco/openWearable/MainActivityTest.java b/open_wearable/android/app/src/androidTest/java/edu/kit/teco/openWearable/MainActivityTest.java new file mode 100644 index 000000000..1214fb702 --- /dev/null +++ b/open_wearable/android/app/src/androidTest/java/edu/kit/teco/openWearable/MainActivityTest.java @@ -0,0 +1,36 @@ +package edu.kit.teco.openWearable; + +import androidx.test.platform.app.InstrumentationRegistry; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.Parameterized; +import org.junit.runners.Parameterized.Parameters; + +import pl.leancode.patrol.PatrolJUnitRunner; + +/** Runs every discovered Dart Patrol test as an Android instrumentation test. */ +@RunWith(Parameterized.class) +public class MainActivityTest { + @Parameters(name = "{0}") + public static Object[] testCases() { + PatrolJUnitRunner instrumentation = + (PatrolJUnitRunner) InstrumentationRegistry.getInstrumentation(); + instrumentation.setUp(MainActivity.class); + instrumentation.waitForPatrolAppService(); + return instrumentation.listDartTests(); + } + + private final String dartTestName; + + public MainActivityTest(String dartTestName) { + this.dartTestName = dartTestName; + } + + @Test + public void runDartTest() { + PatrolJUnitRunner instrumentation = + (PatrolJUnitRunner) InstrumentationRegistry.getInstrumentation(); + instrumentation.runDartTest(dartTestName); + } +} diff --git a/open_wearable/android/app/src/debug/res/values/strings.xml b/open_wearable/android/app/src/debug/res/values/strings.xml new file mode 100644 index 000000000..a4723d769 --- /dev/null +++ b/open_wearable/android/app/src/debug/res/values/strings.xml @@ -0,0 +1,4 @@ + + + OpenWearables Test + diff --git a/open_wearable/android/app/src/main/AndroidManifest.xml b/open_wearable/android/app/src/main/AndroidManifest.xml index 744041532..a2a93bd10 100644 --- a/open_wearable/android/app/src/main/AndroidManifest.xml +++ b/open_wearable/android/app/src/main/AndroidManifest.xml @@ -1,5 +1,5 @@ - +