From 69b2d504934eab4e69b7ef9a574c6c7560cee54b Mon Sep 17 00:00:00 2001 From: Allan Wang Date: Mon, 15 Jun 2020 20:11:12 -0700 Subject: Update AS and add hilt usage --- sample/build.gradle | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) (limited to 'sample/build.gradle') diff --git a/sample/build.gradle b/sample/build.gradle index 96ed78f..b36e3f5 100644 --- a/sample/build.gradle +++ b/sample/build.gradle @@ -2,8 +2,10 @@ import kau.Dependencies apply plugin: 'com.android.application' apply plugin: 'kotlin-android' +apply plugin: 'kotlin-kapt' apply plugin: 'kotlin-android-extensions' apply plugin: 'com.github.triplet.play' +apply plugin: 'dagger.hilt.android.plugin' play { serviceAccountCredentials = file('../files/gplay-keys.json') @@ -135,12 +137,16 @@ dependencies { implementation project(':searchview') implementation project(':mediapicker') + implementation "com.google.dagger:hilt-android:2.28-alpha" + kapt "com.google.dagger:hilt-android-compiler:2.28-alpha" + implementation Dependencies.materialDialog("input") - implementation Dependencies.koin testImplementation Dependencies.kotlinTest testImplementation Dependencies.junit - testImplementation Dependencies.koinTest + testImplementation 'com.google.dagger:hilt-android-testing:2.28-alpha' + kaptTest 'com.google.dagger:hilt-android-compiler:2.28-alpha' + androidTestImplementation Dependencies.kotlinTest androidTestImplementation Dependencies.espresso @@ -148,5 +154,6 @@ dependencies { androidTestImplementation Dependencies.espresso("contrib") androidTestImplementation Dependencies.testRules androidTestImplementation Dependencies.testRunner - androidTestImplementation Dependencies.koinTest + androidTestImplementation 'com.google.dagger:hilt-android-testing:2.28-alpha' + kaptAndroidTest 'com.google.dagger:hilt-android-compiler:2.28-alpha' } -- cgit v1.2.3 From cd24bc8175938ff289c48a6ec3bb956cc22fb79e Mon Sep 17 00:00:00 2001 From: Allan Wang Date: Sun, 21 Jun 2020 22:13:56 -0700 Subject: Update deps and add base test class --- buildSrc/src/main/kotlin/kau/Versions.kt | 9 +++++---- sample/build.gradle | 18 ++++++++++-------- .../kotlin/ca/allanwang/kau/sample/BaseTest.kt | 17 +++++++++++++++++ .../kotlin/ca/allanwang/kau/sample/KPrefViewTest.kt | 15 ++------------- 4 files changed, 34 insertions(+), 25 deletions(-) create mode 100644 sample/src/androidTest/kotlin/ca/allanwang/kau/sample/BaseTest.kt (limited to 'sample/build.gradle') diff --git a/buildSrc/src/main/kotlin/kau/Versions.kt b/buildSrc/src/main/kotlin/kau/Versions.kt index e6bccc8..f4ca30d 100644 --- a/buildSrc/src/main/kotlin/kau/Versions.kt +++ b/buildSrc/src/main/kotlin/kau/Versions.kt @@ -60,15 +60,16 @@ object Versions { const val leakCanary = "2.2" // https://mvnrepository.com/artifact/androidx.test.espresso/espresso-core?repo=google - const val espresso = "3.2.0" + const val espresso = "3.3.0-rc01" // https://mvnrepository.com/artifact/org.junit.jupiter/junit-jupiter-api - const val junit = "4.12" + const val junit = "4.13" - const val testRunner = "1.1.0" + // https://mvnrepository.com/artifact/androidx.test.ext/junit + const val testRunner = "1.1.2-rc01" // https://mvnrepository.com/artifact/androidx.test/rules?repo=google - const val testRules = "1.2.0" + const val testRules = "1.3.0-rc01" // Keep version for now, see https://github.com/diffplug/spotless/issues/521 // https://github.com/diffplug/spotless/blob/master/plugin-gradle/CHANGES.md diff --git a/sample/build.gradle b/sample/build.gradle index b36e3f5..2414487 100644 --- a/sample/build.gradle +++ b/sample/build.gradle @@ -101,14 +101,16 @@ android { main.res.srcDirs += 'src/main/res-public' } - testOptions.unitTests { - // Don't throw runtime exceptions for android calls that are not mocked - returnDefaultValues = true - - // Always show the result of every unit test, even if it passes. - all { - testLogging { - events 'passed', 'skipped', 'failed', 'standardOut', 'standardError' + testOptions { + unitTests { + // Don't throw runtime exceptions for android calls that are not mocked + returnDefaultValues = true + + // Always show the result of every unit test, even if it passes. + all { + testLogging { + events 'passed', 'skipped', 'failed', 'standardOut', 'standardError' + } } } } diff --git a/sample/src/androidTest/kotlin/ca/allanwang/kau/sample/BaseTest.kt b/sample/src/androidTest/kotlin/ca/allanwang/kau/sample/BaseTest.kt new file mode 100644 index 0000000..0f19b05 --- /dev/null +++ b/sample/src/androidTest/kotlin/ca/allanwang/kau/sample/BaseTest.kt @@ -0,0 +1,17 @@ +package ca.allanwang.kau.sample + +import dagger.hilt.android.testing.HiltAndroidRule +import org.junit.Rule +import kotlin.test.BeforeTest + +abstract class BaseTest { + @Suppress("LeakingThis") + @get:Rule + val hiltRule: HiltAndroidRule = + HiltAndroidRule(this) + + @BeforeTest + fun before() { + hiltRule.inject() + } +} \ No newline at end of file diff --git a/sample/src/androidTest/kotlin/ca/allanwang/kau/sample/KPrefViewTest.kt b/sample/src/androidTest/kotlin/ca/allanwang/kau/sample/KPrefViewTest.kt index 91c98e7..a8475b3 100644 --- a/sample/src/androidTest/kotlin/ca/allanwang/kau/sample/KPrefViewTest.kt +++ b/sample/src/androidTest/kotlin/ca/allanwang/kau/sample/KPrefViewTest.kt @@ -25,13 +25,9 @@ import androidx.test.espresso.matcher.BoundedMatcher import androidx.test.espresso.matcher.ViewMatchers.withChild import androidx.test.espresso.matcher.ViewMatchers.withText import androidx.test.ext.junit.runners.AndroidJUnit4 -import androidx.test.filters.MediumTest import androidx.test.rule.ActivityTestRule -import dagger.hilt.android.testing.HiltAndroidRule import dagger.hilt.android.testing.HiltAndroidTest -import dagger.hilt.android.testing.HiltTestApplication import dagger.hilt.android.testing.UninstallModules -import kotlin.test.BeforeTest import kotlin.test.assertFalse import kotlin.test.assertTrue import org.hamcrest.BaseMatcher @@ -54,22 +50,15 @@ import javax.inject.Inject @RunWith(AndroidJUnit4::class) @HiltAndroidTest @UninstallModules(PrefFactoryModule::class) -class KPrefViewTest { +class KPrefViewTest : BaseTest() { val activity: ActivityTestRule = ActivityTestRule(MainActivity::class.java) - val hiltRule = HiltAndroidRule(this) - @get:Rule - val rule: TestRule = RuleChain.outerRule(hiltRule).around(SampleTestRule()).around(activity) + val rule: TestRule = RuleChain.outerRule(SampleTestRule()).around(activity) @Inject lateinit var pref: KPrefSample - @BeforeTest - fun before() { - hiltRule.inject() - } - fun verifyCheck(checked: Boolean): Matcher { return object : BoundedMatcher(View::class.java) { -- cgit v1.2.3 From 3f28748f959dedb6f7baee7c1c27e343080e8c3f Mon Sep 17 00:00:00 2001 From: Allan Wang Date: Sat, 27 Jun 2020 14:36:40 -0700 Subject: Update AS and add hilt version info --- buildSrc/src/main/kotlin/kau/Dependencies.kt | 12 ++++++++++ buildSrc/src/main/kotlin/kau/Versions.kt | 7 ++++-- sample/build.gradle | 26 ++++++---------------- .../kotlin/ca/allanwang/kau/sample/BaseTest.kt | 17 -------------- .../ca/allanwang/kau/sample/KPrefViewTest.kt | 1 + .../kotlin/ca/allanwang/kau/sample/TestModules.kt | 15 ------------- .../ca/allanwang/kau/sample/test/BaseTest.kt | 17 ++++++++++++++ .../ca/allanwang/kau/sample/test/TestModules.kt | 15 +++++++++++++ 8 files changed, 57 insertions(+), 53 deletions(-) delete mode 100644 sample/src/androidTest/kotlin/ca/allanwang/kau/sample/BaseTest.kt delete mode 100644 sample/src/androidTest/kotlin/ca/allanwang/kau/sample/TestModules.kt create mode 100644 sample/src/androidTest/kotlin/ca/allanwang/kau/sample/test/BaseTest.kt create mode 100644 sample/src/androidTest/kotlin/ca/allanwang/kau/sample/test/TestModules.kt (limited to 'sample/build.gradle') diff --git a/buildSrc/src/main/kotlin/kau/Dependencies.kt b/buildSrc/src/main/kotlin/kau/Dependencies.kt index d7a3757..b59ba91 100644 --- a/buildSrc/src/main/kotlin/kau/Dependencies.kt +++ b/buildSrc/src/main/kotlin/kau/Dependencies.kt @@ -59,6 +59,18 @@ object Dependencies { @JvmStatic fun koin(type: String) = "org.koin:koin-$type:${Versions.koin}" + @JvmField + val hilt = "com.google.dagger:hilt-android:${Versions.hilt}" + + @JvmField + val hiltCompiler = hilt("compiler") + + @JvmField + val hiltTest = hilt("testing") + + @JvmStatic + fun hilt(type: String) = "com.google.dagger:hilt-android-$type:${Versions.hilt}" + const val junit = "junit:junit:${Versions.junit}" const val coroutines = "org.jetbrains.kotlinx:kotlinx-coroutines-android:${Versions.coroutines}" diff --git a/buildSrc/src/main/kotlin/kau/Versions.kt b/buildSrc/src/main/kotlin/kau/Versions.kt index f4ca30d..f0ed129 100644 --- a/buildSrc/src/main/kotlin/kau/Versions.kt +++ b/buildSrc/src/main/kotlin/kau/Versions.kt @@ -54,7 +54,10 @@ object Versions { const val materialDialog = "3.3.0" // https://github.com/InsertKoinIO/koin/blob/master/CHANGELOG.md - const val koin = "2.1.5" + const val koin = "2.1.6" + + // https://mvnrepository.com/artifact/com.google.dagger/hilt-android + const val hilt = "2.28.1-alpha" // https://square.github.io/leakcanary/changelog/ const val leakCanary = "2.2" @@ -82,7 +85,7 @@ object Versions { const val bugsnagPlugin="4.7.4" // https://mvnrepository.com/artifact/com.android.tools.build/gradle?repo=google - const val gradlePlugin = "4.1.0-beta01" + const val gradlePlugin = "4.1.0-beta02" // https://github.com/dcendents/android-maven-gradle-plugin/releases const val mavenPlugin = "2.1" // https://github.com/Triple-T/gradle-play-publisher/releases diff --git a/sample/build.gradle b/sample/build.gradle index 2414487..d620c2a 100644 --- a/sample/build.gradle +++ b/sample/build.gradle @@ -109,19 +109,7 @@ android { // Always show the result of every unit test, even if it passes. all { testLogging { - events 'passed', 'skipped', 'failed', 'standardOut', 'standardError' - } - } - } - } - - // See https://github.com/facebook/flipper/issues/146 - configurations.all { - resolutionStrategy.eachDependency { DependencyResolveDetails details -> - def requested = details.requested - if (requested.group == "com.android.support") { - if (!requested.name.startsWith("multidex")) { - details.useVersion "26.+" + events 'skipped', 'failed', 'standardOut', 'standardError' } } } @@ -139,15 +127,15 @@ dependencies { implementation project(':searchview') implementation project(':mediapicker') - implementation "com.google.dagger:hilt-android:2.28-alpha" - kapt "com.google.dagger:hilt-android-compiler:2.28-alpha" + implementation Dependencies.hilt + kapt Dependencies.hiltCompiler implementation Dependencies.materialDialog("input") testImplementation Dependencies.kotlinTest testImplementation Dependencies.junit - testImplementation 'com.google.dagger:hilt-android-testing:2.28-alpha' - kaptTest 'com.google.dagger:hilt-android-compiler:2.28-alpha' + testImplementation Dependencies.hiltTest + kaptTest Dependencies.hiltCompiler androidTestImplementation Dependencies.kotlinTest @@ -156,6 +144,6 @@ dependencies { androidTestImplementation Dependencies.espresso("contrib") androidTestImplementation Dependencies.testRules androidTestImplementation Dependencies.testRunner - androidTestImplementation 'com.google.dagger:hilt-android-testing:2.28-alpha' - kaptAndroidTest 'com.google.dagger:hilt-android-compiler:2.28-alpha' + testImplementation Dependencies.hiltTest + kaptTest Dependencies.hiltCompiler } diff --git a/sample/src/androidTest/kotlin/ca/allanwang/kau/sample/BaseTest.kt b/sample/src/androidTest/kotlin/ca/allanwang/kau/sample/BaseTest.kt deleted file mode 100644 index 0f19b05..0000000 --- a/sample/src/androidTest/kotlin/ca/allanwang/kau/sample/BaseTest.kt +++ /dev/null @@ -1,17 +0,0 @@ -package ca.allanwang.kau.sample - -import dagger.hilt.android.testing.HiltAndroidRule -import org.junit.Rule -import kotlin.test.BeforeTest - -abstract class BaseTest { - @Suppress("LeakingThis") - @get:Rule - val hiltRule: HiltAndroidRule = - HiltAndroidRule(this) - - @BeforeTest - fun before() { - hiltRule.inject() - } -} \ No newline at end of file diff --git a/sample/src/androidTest/kotlin/ca/allanwang/kau/sample/KPrefViewTest.kt b/sample/src/androidTest/kotlin/ca/allanwang/kau/sample/KPrefViewTest.kt index a8475b3..bfdcfff 100644 --- a/sample/src/androidTest/kotlin/ca/allanwang/kau/sample/KPrefViewTest.kt +++ b/sample/src/androidTest/kotlin/ca/allanwang/kau/sample/KPrefViewTest.kt @@ -26,6 +26,7 @@ import androidx.test.espresso.matcher.ViewMatchers.withChild import androidx.test.espresso.matcher.ViewMatchers.withText import androidx.test.ext.junit.runners.AndroidJUnit4 import androidx.test.rule.ActivityTestRule +import ca.allanwang.kau.sample.test.BaseTest import dagger.hilt.android.testing.HiltAndroidTest import dagger.hilt.android.testing.UninstallModules import kotlin.test.assertFalse diff --git a/sample/src/androidTest/kotlin/ca/allanwang/kau/sample/TestModules.kt b/sample/src/androidTest/kotlin/ca/allanwang/kau/sample/TestModules.kt deleted file mode 100644 index 061af50..0000000 --- a/sample/src/androidTest/kotlin/ca/allanwang/kau/sample/TestModules.kt +++ /dev/null @@ -1,15 +0,0 @@ -package ca.allanwang.kau.sample - -import ca.allanwang.kau.kpref.KPrefFactory -import ca.allanwang.kau.kpref.KPrefFactoryInMemory -import dagger.Module -import dagger.Provides -import dagger.hilt.InstallIn -import dagger.hilt.android.components.ApplicationComponent - -@Module -@InstallIn(ApplicationComponent::class) -object PrefFactoryTestModule { - @Provides - fun factory(): KPrefFactory = KPrefFactoryInMemory -} \ No newline at end of file diff --git a/sample/src/androidTest/kotlin/ca/allanwang/kau/sample/test/BaseTest.kt b/sample/src/androidTest/kotlin/ca/allanwang/kau/sample/test/BaseTest.kt new file mode 100644 index 0000000..c3a17ea --- /dev/null +++ b/sample/src/androidTest/kotlin/ca/allanwang/kau/sample/test/BaseTest.kt @@ -0,0 +1,17 @@ +package ca.allanwang.kau.sample.test + +import dagger.hilt.android.testing.HiltAndroidRule +import org.junit.Rule +import kotlin.test.BeforeTest + +abstract class BaseTest { + @Suppress("LeakingThis") + @get:Rule + val hiltRule: HiltAndroidRule = + HiltAndroidRule(this) + + @BeforeTest + fun before() { + hiltRule.inject() + } +} \ No newline at end of file diff --git a/sample/src/androidTest/kotlin/ca/allanwang/kau/sample/test/TestModules.kt b/sample/src/androidTest/kotlin/ca/allanwang/kau/sample/test/TestModules.kt new file mode 100644 index 0000000..4e49810 --- /dev/null +++ b/sample/src/androidTest/kotlin/ca/allanwang/kau/sample/test/TestModules.kt @@ -0,0 +1,15 @@ +package ca.allanwang.kau.sample.test + +import ca.allanwang.kau.kpref.KPrefFactory +import ca.allanwang.kau.kpref.KPrefFactoryInMemory +import dagger.Module +import dagger.Provides +import dagger.hilt.InstallIn +import dagger.hilt.android.components.ApplicationComponent + +@Module +@InstallIn(ApplicationComponent::class) +object PrefFactoryTestModule { + @Provides + fun factory(): KPrefFactory = KPrefFactoryInMemory +} \ No newline at end of file -- cgit v1.2.3