aboutsummaryrefslogtreecommitdiff
path: root/sample/src
diff options
context:
space:
mode:
authorAllan Wang <me@allanwang.ca>2020-06-21 22:13:56 -0700
committerAllan Wang <me@allanwang.ca>2020-06-21 22:13:56 -0700
commitcd24bc8175938ff289c48a6ec3bb956cc22fb79e (patch)
tree742e4385983c02dcca48534c665fd73738dbd277 /sample/src
parent69b2d504934eab4e69b7ef9a574c6c7560cee54b (diff)
downloadkau-cd24bc8175938ff289c48a6ec3bb956cc22fb79e.tar.gz
kau-cd24bc8175938ff289c48a6ec3bb956cc22fb79e.tar.bz2
kau-cd24bc8175938ff289c48a6ec3bb956cc22fb79e.zip
Update deps and add base test class
Diffstat (limited to 'sample/src')
-rw-r--r--sample/src/androidTest/kotlin/ca/allanwang/kau/sample/BaseTest.kt17
-rw-r--r--sample/src/androidTest/kotlin/ca/allanwang/kau/sample/KPrefViewTest.kt15
2 files changed, 19 insertions, 13 deletions
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<MainActivity> = 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<View> {
return object : BoundedMatcher<View, View>(View::class.java) {