aboutsummaryrefslogtreecommitdiff
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
parent69b2d504934eab4e69b7ef9a574c6c7560cee54b (diff)
downloadkau-cd24bc8175938ff289c48a6ec3bb956cc22fb79e.tar.gz
kau-cd24bc8175938ff289c48a6ec3bb956cc22fb79e.tar.bz2
kau-cd24bc8175938ff289c48a6ec3bb956cc22fb79e.zip
Update deps and add base test class
-rw-r--r--buildSrc/src/main/kotlin/kau/Versions.kt9
-rw-r--r--sample/build.gradle18
-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
4 files changed, 34 insertions, 25 deletions
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<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) {