Permalink
Browse files

Move data tests in :data-android

We now use Robolectric to run them, which makes
them much faster.
  • Loading branch information...
chrisbanes committed Oct 17, 2018
1 parent 464d743 commit b1231794c151dc7e2ad00499c619679130654fe5
@@ -188,8 +188,15 @@ dependencies {

implementation 'com.cantrowitz:rxbroadcast:2.0.0'

implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8:${versions.kotlin}"
implementation "org.jetbrains.kotlin:kotlin-reflect:${versions.kotlin}"

implementation "org.jetbrains.kotlinx:kotlinx-coroutines-core:${versions.coroutines}"
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-rx2:${versions.coroutines}"
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-android:${versions.coroutines}"

implementation "org.jetbrains:annotations:16.0.3"

implementation "com.google.dagger:dagger-android:${versions.dagger}"
implementation "com.google.dagger:dagger-android-support:${versions.dagger}"
kapt "com.google.dagger:dagger-compiler:${versions.dagger}"
@@ -210,26 +217,16 @@ dependencies {

implementation 'com.github.rubensousa:gravitysnaphelper:1.5'

testImplementation 'junit:junit:4.12'

androidTestImplementation "androidx.test:runner:${versions.androidx.test_runner}"
androidTestImplementation "androidx.test:rules:${versions.androidx.test_rules}"
androidTestImplementation "androidx.test.espresso:espresso-core:${versions.espresso}"
androidTestImplementation "androidx.room:room-runtime:${versions.androidx.room}"
androidTestImplementation 'com.linkedin.dexmaker:dexmaker-mockito:2.19.1'

debugImplementation "nl.littlerobots.rxlint:rxlint:${versions.rxlint}"

implementation "com.google.firebase:firebase-core:${versions.firebase}"
implementation 'com.crashlytics.sdk.android:crashlytics:2.9.5'

implementation "org.jetbrains:annotations:16.0.3"

implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8:${versions.kotlin}"
implementation "org.jetbrains.kotlin:kotlin-reflect:${versions.kotlin}"
testImplementation "junit:junit:${versions.junit}"

implementation "org.jetbrains.kotlinx:kotlinx-coroutines-core:${versions.coroutines}"
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-rx2:${versions.coroutines}"
androidTestImplementation "androidx.test:runner:${versions.androidx.test_runner}"
androidTestImplementation "androidx.test:rules:${versions.androidx.test_rules}"
androidTestImplementation "androidx.test.espresso:espresso-core:${versions.espresso}"
}

def getGitHash() {
@@ -51,6 +51,9 @@ buildscript {
'threetenbp' : '1.3.7',
'threetenabp' : '1.1.0',
'retrofit' : '2.4.0',
'junit' : '4.12',
'robolectric' : '4.0-beta-1',
'mockito_kotlin' : '2.0.0-RC3'
]

ext.buildConfig = [
@@ -39,6 +39,12 @@ android {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}

testOptions {
unitTests {
includeAndroidResources = true
}
}
}

dependencies {
@@ -53,4 +59,13 @@ dependencies {
implementation "androidx.paging:paging-runtime:${versions.androidx.paging}"

kapt "com.google.dagger:dagger-compiler:${versions.dagger}"

testImplementation "junit:junit:${versions.junit}"
testImplementation "org.robolectric:robolectric:${versions.robolectric}"
testImplementation "com.nhaarman.mockitokotlin2:mockito-kotlin:${versions.mockito_kotlin}"
testImplementation "androidx.test:core:1.0.0-beta02"
testImplementation "androidx.arch.core:core-testing:2.0.0"

testImplementation "org.threeten:threetenbp:${versions.threetenbp}"
testImplementation "org.jetbrains.kotlinx:kotlinx-coroutines-android:${versions.coroutines}"
}
@@ -16,29 +16,33 @@

package app.tivi.utils

import android.content.Context
import androidx.arch.core.executor.testing.InstantTaskExecutorRule
import androidx.room.Room
import androidx.test.InstrumentationRegistry
import androidx.test.runner.AndroidJUnit4
import androidx.test.core.app.ApplicationProvider
import app.tivi.data.TiviDatabase
import com.jakewharton.threetenabp.AndroidThreeTen
import org.junit.After
import org.junit.Before
import org.junit.Rule
import org.junit.runner.RunWith
import org.robolectric.RobolectricTestRunner
import java.io.IOException

@RunWith(AndroidJUnit4::class)
@RunWith(RobolectricTestRunner::class)
abstract class BaseDatabaseTest {
@Rule
@JvmField
val instantTaskExecutorRule = InstantTaskExecutorRule()

lateinit var db: TiviDatabase
private set

@Before
open fun setup() {
val context = InstrumentationRegistry.getTargetContext()
val context = ApplicationProvider.getApplicationContext<Context>()
db = Room.inMemoryDatabaseBuilder(context, TiviDatabase::class.java)
.allowMainThreadQueries()
.build()

AndroidThreeTen.init(context)
}

@After
@@ -17,7 +17,7 @@
package app.tivi.utils

import app.tivi.util.AppCoroutineDispatchers
import kotlinx.coroutines.android.UI
import kotlinx.coroutines.Dispatchers.Main

// Everything on the UI
val testCoroutineDispatchers = AppCoroutineDispatchers(UI, UI, UI)
val testCoroutineDispatchers = AppCoroutineDispatchers(Main, Main, Main)
@@ -18,9 +18,9 @@
apply plugin: 'kotlin'

dependencies {
implementation project(":base")
implementation project(":trakt")
implementation project(":tmdb")
compile project(":base")
compile project(":trakt")
compile project(":tmdb")

compile "androidx.room:room-common:${versions.androidx.room}"
compile "androidx.paging:paging-common:${versions.androidx.paging}"
@@ -15,10 +15,13 @@ org.gradle.parallel=true
org.gradle.configureondemand=true
org.gradle.caching=true

# Enable D8 desugar / R8
android.enableD8.desugaring=true
# Enable R8
android.enableR8=true

# AndroidX
android.useAndroidX=true
android.enableJetifier=true
android.enableJetifier=true

# Enable Robolectric to use the same resources as Android
android.enableUnitTestBinaryResources=true

0 comments on commit b123179

Please sign in to comment.