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 --- .../kotlin/ca/allanwang/kau/sample/BaseTest.kt | 17 +++++++++++++++++ .../kotlin/ca/allanwang/kau/sample/KPrefViewTest.kt | 15 ++------------- 2 files changed, 19 insertions(+), 13 deletions(-) create mode 100644 sample/src/androidTest/kotlin/ca/allanwang/kau/sample/BaseTest.kt (limited to 'sample/src/androidTest') 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