Skip to content

Android: working android tests for architecture samples #5219

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

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 8 additions & 7 deletions example/androidlib/java/5-R8/build.mill
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ object androidSdkModule0 extends AndroidSdkModule { // <1>
def buildToolsVersion = "35.0.0"
}

object app extends AndroidAppModule { // <2>
object app extends AndroidR8AppModule { // <2>
def androidSdkModule = mill.define.ModuleRef(androidSdkModule0)
def androidMinSdk = 19
def androidCompileSdk = 35
Expand Down Expand Up @@ -61,21 +61,22 @@ object app extends AndroidAppModule { // <2>
}

// Instrumented tests (runs on emulator)
object it extends AndroidAppInstrumentedTests with AndroidTestModule.AndroidJUnit {
object it extends AndroidAppInstrumentedTests with AndroidR8AppModule
with AndroidTestModule.AndroidJUnit {
def androidSdkModule = mill.define.ModuleRef(androidSdkModule0)

override def androidIsDebug: T[Boolean] = Task {
false
}

override def androidReleaseSettings: T[AndroidBuildTypeSettings] = Task {
AndroidBuildTypeSettings(isMinifyEnabled = false)
AndroidBuildTypeSettings(isMinifyEnabled = false).withProguardLocalFiles(
Seq(
moduleDir / "test-proguard-rules.pro"
)
)
}

/* TODO currently the dependency resolution ignores the platform type and kotlinx-coroutines-core has
* conflicting classes with kotlinx-coroutines-core-jvm . Remove the exclusions once the dependency
* resolution resolves conflicts between androidJvm and jvm platform types
*/
def mvnDeps = super.mvnDeps() ++ Seq(
mvn"androidx.test.ext:junit:1.2.1",
mvn"androidx.test:runner:1.6.2",
Expand Down
18 changes: 0 additions & 18 deletions example/androidlib/kotlin/1-hello-kotlin/build.mill
Original file line number Diff line number Diff line change
Expand Up @@ -43,16 +43,6 @@ object app extends AndroidAppKotlinModule {

override def androidIsDebug: T[Boolean] = Task { false }

override def androidReleaseSettings: T[AndroidBuildTypeSettings] = Task {
super.androidReleaseSettings()
.withDefaultProguardFile("proguard-android.txt")
.withProguardLocalFiles(
Seq(
moduleDir / "proguard-rules.pro"
)
)
}

object test extends AndroidAppKotlinTests with TestModule.Junit4 {
def junit4Version = "4.13.2"
}
Expand All @@ -68,14 +58,6 @@ object app extends AndroidAppKotlinModule {
false
}

override def androidReleaseSettings: T[AndroidBuildTypeSettings] = Task {
AndroidBuildTypeSettings(isMinifyEnabled = false)
}

/* TODO currently the dependency resolution ignores the platform type and kotlinx-coroutines-core has
* conflicting classes with kotlinx-coroutines-core-jvm . Remove the exclusions once the dependency
* resolution resolves conflicts between androidJvm and jvm platform types
*/
def mvnDeps = super.mvnDeps() ++ Seq(
mvn"androidx.test.ext:junit:1.2.1",
mvn"androidx.test:runner:1.6.2",
Expand Down
91 changes: 86 additions & 5 deletions example/thirdparty/androidtodo/build.mill
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,30 @@ object androidSdkModule0 extends AndroidSdkModule {
}

// Mill configuration for the Android Todo App project.
object app extends AndroidAppKotlinModule with AndroidBuildConfig with AndroidHiltSupport {
object app extends AndroidAppKotlinModule with AndroidR8AppModule with AndroidBuildConfig
with AndroidHiltSupport {

def kotlinVersion = Versions.kotlinVersion
def kotlinLanguageVersion = Versions.kotlinLanguageVersion
def kspVersion = Versions.kspVersion

override def androidDebugSettings: T[AndroidBuildTypeSettings] = Task {
AndroidBuildTypeSettings(
isMinifyEnabled = false,
isShrinkEnabled = false
).withDefaultProguardFile("proguard-android.txt")
.withProguardLocalFiles(
Seq(
moduleDir / "proguard-rules.pro"
)
)
}

// TODO consider using a debug module
def debugSources = Task.Sources("src/debug/java")

override def sources = super.sources() ++ debugSources()

def androidApplicationNamespace = "com.example.android.architecture.blueprints.todoapp"
// TODO change this to com.example.android.architecture.blueprints.main when mill supports build variants
def androidApplicationId = "com.example.android.architecture.blueprints.main"
Expand All @@ -42,6 +60,7 @@ object app extends AndroidAppKotlinModule with AndroidBuildConfig with AndroidHi
mvn"androidx.core:core-ktx:1.15.0",
mvn"androidx.appcompat:appcompat:1.7.0",
mvn"androidx.annotation:annotation:1.9.1",
mvn"org.jetbrains.kotlinx:kotlinx-coroutines-android:1.9.0",
mvn"com.jakewharton.timber:timber:5.0.1",
mvn"androidx.test.espresso:espresso-idling-resource:3.6.1",
mvn"androidx.room:room-runtime:2.6.1",
Expand Down Expand Up @@ -73,7 +92,10 @@ object app extends AndroidAppKotlinModule with AndroidBuildConfig with AndroidHi
mvn"androidx.hilt:hilt-navigation-compose:1.2.0",
mvn"com.google.accompanist:accompanist-swiperefresh:0.36.0",
mvn"androidx.customview:customview-poolingcontainer:1.0.0",
mvn"androidx.tracing:tracing:1.2.0"
mvn"androidx.tracing:tracing:1.2.0",
// debug
mvn"androidx.compose.ui:ui-tooling:1.7.6",
mvn"androidx.compose.ui:ui-test-manifest:1.7.6"
)

def kotlinSymbolProcessors: T[Seq[Dep]] = Seq(
Expand Down Expand Up @@ -110,11 +132,63 @@ object app extends AndroidAppKotlinModule with AndroidBuildConfig with AndroidHi
)
}

// TODO support instrumented tests on Hilt setups
object androidTest extends AndroidAppKotlinInstrumentedTests
with AndroidTestModule.AndroidJUnit with AndroidHiltSupport {
object androidTest extends AndroidAppKotlinInstrumentedTests with AndroidR8AppModule
with AndroidHiltSupport {

override def kotlinLanguageVersion = Versions.kotlinLanguageVersion

def moduleDeps = super.moduleDeps ++ Seq(`shared-test`)

def testFramework = "com.example.android.architecture.blueprints.todoapp.CustomTestRunner"

def androidEnableCompose = true

override def kspVersion = Versions.kspVersion

override def androidDebugSettings: T[AndroidBuildTypeSettings] = Task {
AndroidBuildTypeSettings(
isMinifyEnabled = false,
isShrinkEnabled = false
).withDefaultProguardFile("proguard-android.txt")
.withProguardLocalFiles(
Seq(
moduleDir / "proguardTest-rules.pro",
moduleDir / "proguard-rules.pro"
)
)
}

def mvnDeps = super.mvnDeps() ++ Seq(
// Dependencies for Android unit tests
mvn"androidx.compose:compose-bom:2024.12.01",
mvn"junit:junit:4.13.2",
mvn"org.jetbrains.kotlinx:kotlinx-coroutines-test:1.9.0",
mvn"org.jetbrains.kotlinx:kotlinx-coroutines-android:1.9.0",
mvn"androidx.compose.ui:ui-test-junit4:1.7.6",
// AndroidX Test - Instrumented testing
mvn"androidx.test:core-ktx:1.6.1",
mvn"androidx.test.ext:junit-ktx:1.2.1",
mvn"androidx.test:rules:1.6.1",
mvn"androidx.room:room-testing:2.6.1",
mvn"androidx.arch.core:core-testing:2.2.0",
mvn"androidx.navigation:navigation-testing:2.8.5",
mvn"androidx.test.espresso:espresso-core:3.6.1",
mvn"androidx.test.espresso:espresso-contrib:3.6.1",
mvn"androidx.test.espresso:espresso-intents:3.6.1",
mvn"androidx.test.espresso:espresso-idling-resource:3.6.1",
mvn"androidx.test.espresso.idling:idling-concurrent:3.6.1",
// AndroidX Test - Hilt testing
mvn"com.google.dagger:hilt-android-testing:2.56",
// debug
mvn"androidx.compose.ui:ui-tooling:1.7.6",
mvn"androidx.compose.ui:ui-test-manifest:1.7.6"
)

def kotlinSymbolProcessors: T[Seq[Dep]] = Seq(
mvn"androidx.room:room-compiler:2.6.1",
mvn"com.google.dagger:hilt-android-compiler:2.56"
)

}

}
Expand Down Expand Up @@ -186,6 +260,13 @@ object `shared-test` extends AndroidKotlinModule with AndroidHiltSupport {
"Complete"
]

> ./mill app.androidTest

> cat out/app/androidTest/testForked.dest/test-report.xml
<?xml version='1.0' encoding='UTF-8'?>
<testsuites tests="38" failures="0" errors="0" skipped="0" time="...">
...

> ./mill show app.stopAndroidEmulator

> ./mill show app.deleteAndroidVirtualDevice
Expand Down
Loading