From 11d07a6d3f097108e367a94307d979e365690b08 Mon Sep 17 00:00:00 2001 From: Josef Raska <6277721+jraska@users.noreply.github.com> Date: Sun, 11 Apr 2021 21:15:14 +0200 Subject: [PATCH 1/5] Run instrumented tests in modules --- feature/about/build.gradle | 13 +++++++++++ .../client/about/VersionInfoModelTest.kt | 23 +++++++++++++++++++ .../github/client/about/VersionInfoModel.kt | 2 +- 3 files changed, 37 insertions(+), 1 deletion(-) create mode 100644 feature/about/src/androidTest/java/com/jraska/github/client/about/VersionInfoModelTest.kt diff --git a/feature/about/build.gradle b/feature/about/build.gradle index 9eabd3ac..363435cf 100644 --- a/feature/about/build.gradle +++ b/feature/about/build.gradle @@ -6,6 +6,8 @@ android { compileSdkVersion 30 defaultConfig { minSdkVersion 24 + + testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" } compileOptions { @@ -14,6 +16,13 @@ android { } } +// Test will be executed on Firebase Test Lab +if (gradle.startParameter.taskNames.any { it.contains("Firebase") }) { + project(":app").afterEvaluate { + android.sourceSets.androidTest.java.srcDirs += ["./src/androidTest/java"] + } +} + dependencies { implementation project(':core-api') @@ -35,4 +44,8 @@ dependencies { testImplementation 'androidx.arch.core:core-testing:2.1.0' testImplementation 'org.mockito:mockito-core:3.8.0' testImplementation project(':core-testing') + + androidTestImplementation 'junit:junit:4.13.2' + androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0' + androidTestImplementation 'org.assertj:assertj-core:3.19.0' } diff --git a/feature/about/src/androidTest/java/com/jraska/github/client/about/VersionInfoModelTest.kt b/feature/about/src/androidTest/java/com/jraska/github/client/about/VersionInfoModelTest.kt new file mode 100644 index 00000000..16fcac68 --- /dev/null +++ b/feature/about/src/androidTest/java/com/jraska/github/client/about/VersionInfoModelTest.kt @@ -0,0 +1,23 @@ +package com.jraska.github.client.about + +import android.view.LayoutInflater +import android.widget.FrameLayout +import android.widget.TextView + +import androidx.test.platform.app.InstrumentationRegistry +import org.assertj.core.api.Assertions.assertThat +import org.junit.Test + +internal class VersionInfoModelTest { + @Test + fun testBinding() { + val context = InstrumentationRegistry.getInstrumentation().targetContext + val frameLayout = FrameLayout(context) + + val versionInfoModel = VersionInfoModel() + val view = LayoutInflater.from(context).inflate(versionInfoModel.layout, frameLayout) + versionInfoModel.bind(view) + + assertThat(view.findViewById(R.id.version_name_and_code).text).contains("Version") + } +} diff --git a/feature/about/src/main/java/com/jraska/github/client/about/VersionInfoModel.kt b/feature/about/src/main/java/com/jraska/github/client/about/VersionInfoModel.kt index a912765e..46911b26 100644 --- a/feature/about/src/main/java/com/jraska/github/client/about/VersionInfoModel.kt +++ b/feature/about/src/main/java/com/jraska/github/client/about/VersionInfoModel.kt @@ -5,7 +5,7 @@ import android.widget.TextView import androidx.core.content.pm.PackageInfoCompat import com.airbnb.epoxy.SimpleEpoxyModel -internal class VersionInfoModel : SimpleEpoxyModel(R.layout.about_item_version) { +class VersionInfoModel : SimpleEpoxyModel(R.layout.about_item_version) { override fun bind(view: View) { super.bind(view) From 88c220ae98b1ce8e1ca04daafcadb2c51d357140 Mon Sep 17 00:00:00 2001 From: Josef Raska <6277721+jraska@users.noreply.github.com> Date: Sun, 11 Apr 2021 21:26:19 +0200 Subject: [PATCH 2/5] Remove the if --- feature/about/build.gradle | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/feature/about/build.gradle b/feature/about/build.gradle index 363435cf..944b7582 100644 --- a/feature/about/build.gradle +++ b/feature/about/build.gradle @@ -17,10 +17,8 @@ android { } // Test will be executed on Firebase Test Lab -if (gradle.startParameter.taskNames.any { it.contains("Firebase") }) { - project(":app").afterEvaluate { - android.sourceSets.androidTest.java.srcDirs += ["./src/androidTest/java"] - } +project(":app").afterEvaluate { + android.sourceSets.androidTest.java.srcDirs += ["./src/androidTest/java"] } dependencies { From 621ca6638f06c2963cfd5413540f0d5b2a2b9527 Mon Sep 17 00:00:00 2001 From: Josef Raska <6277721+jraska@users.noreply.github.com> Date: Sun, 11 Apr 2021 21:53:43 +0200 Subject: [PATCH 3/5] Remove after evaluate --- feature/about/build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/feature/about/build.gradle b/feature/about/build.gradle index 944b7582..b631374f 100644 --- a/feature/about/build.gradle +++ b/feature/about/build.gradle @@ -17,7 +17,7 @@ android { } // Test will be executed on Firebase Test Lab -project(":app").afterEvaluate { +project(":app") { android.sourceSets.androidTest.java.srcDirs += ["./src/androidTest/java"] } From 8ac4fefb7481915ce254fe020eea58f3d2c4965b Mon Sep 17 00:00:00 2001 From: Josef Raska <6277721+jraska@users.noreply.github.com> Date: Sun, 11 Apr 2021 22:44:01 +0200 Subject: [PATCH 4/5] Try the app configuration from the app module --- app/build.gradle | 8 +++++++- feature/about/build.gradle | 4 +--- .../jraska/github/client/about/VersionInfoModelTest.kt | 2 +- 3 files changed, 9 insertions(+), 5 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index 7b7aacec..cf3a6d4d 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -80,6 +80,12 @@ android { packagingOptions { exclude 'META-INF/licenses/ASM' } + + sourceSets { + androidTest { + java.srcDirs += ["../feature/about/src/androidTest/java"] + } + } } dependencies { @@ -176,7 +182,7 @@ play { } project.afterEvaluate { - if (gradle.startParameter.taskNames.any{ it.startsWith("publishBundle")}) { + if (gradle.startParameter.taskNames.any { it.startsWith("publishBundle") }) { def credentials = System.getenv("PLAY_PUBLISHER_CREDENTIALS") if (credentials == null) { throw new GradleException("PLAY_PUBLISHER_CREDENTIALS not set, cannot release") diff --git a/feature/about/build.gradle b/feature/about/build.gradle index b631374f..591cd0d2 100644 --- a/feature/about/build.gradle +++ b/feature/about/build.gradle @@ -17,9 +17,7 @@ android { } // Test will be executed on Firebase Test Lab -project(":app") { - android.sourceSets.androidTest.java.srcDirs += ["./src/androidTest/java"] -} +//project(":app").android.sourceSets.androidTest.java.srcDirs += ["../feature/about/src/androidTest/java"] dependencies { diff --git a/feature/about/src/androidTest/java/com/jraska/github/client/about/VersionInfoModelTest.kt b/feature/about/src/androidTest/java/com/jraska/github/client/about/VersionInfoModelTest.kt index 16fcac68..52f56796 100644 --- a/feature/about/src/androidTest/java/com/jraska/github/client/about/VersionInfoModelTest.kt +++ b/feature/about/src/androidTest/java/com/jraska/github/client/about/VersionInfoModelTest.kt @@ -10,7 +10,7 @@ import org.junit.Test internal class VersionInfoModelTest { @Test - fun testBinding() { + fun bindsProperly() { val context = InstrumentationRegistry.getInstrumentation().targetContext val frameLayout = FrameLayout(context) From 69951ba836788cd16291be17dd1b400adfb40028 Mon Sep 17 00:00:00 2001 From: Josef Raska <6277721+jraska@users.noreply.github.com> Date: Sun, 11 Apr 2021 22:57:41 +0200 Subject: [PATCH 5/5] Do things from the appp module at the end --- app/build.gradle | 6 ++---- feature/about/build.gradle | 3 --- 2 files changed, 2 insertions(+), 7 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index cf3a6d4d..262d8b14 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -81,10 +81,8 @@ android { exclude 'META-INF/licenses/ASM' } - sourceSets { - androidTest { - java.srcDirs += ["../feature/about/src/androidTest/java"] - } + if (gradle.startParameter.taskNames.any { it.contains("Firebase") }) { + sourceSets.androidTest.java.srcDirs += ["../feature/about/src/androidTest/java"] } } diff --git a/feature/about/build.gradle b/feature/about/build.gradle index 591cd0d2..5a60d0c6 100644 --- a/feature/about/build.gradle +++ b/feature/about/build.gradle @@ -16,9 +16,6 @@ android { } } -// Test will be executed on Firebase Test Lab -//project(":app").android.sourceSets.androidTest.java.srcDirs += ["../feature/about/src/androidTest/java"] - dependencies { implementation project(':core-api')