Невозможно импортировать InstantTaskExecutorRule в моем тестовом примере 'jUnit' даже после добавления зависимости 'core-testing' - тестирование Android - PullRequest
1 голос
/ 07 мая 2019

Я пишу тестовые случаи для моего LoginViewModel. Где я хочу выполнить setValue() операцию на моем MutableLiveData.

Чтобы избежать Метод getMainLooper в android.os.Looper не осмеивается Исключение Я пытаюсь добавить следующее Rule в мой файл ViewModel внутри тестовой папки .

@Rule public InstantTaskExecutorRule mInstantTaskExecutorRule = new InstantTaskExecutorRule();

для этого я добавил следующую зависимость:

androidTestImplementation 'android.arch.core:core-testing:1.1.1' as dependency.

Но все же я не могу импортировать InstantTaskExecutorRule в моем файле LoginViewModelTest. В чем может быть проблема?

Несмотря на то, что он импортируется в папку androidTest , в которую мы пишем тесты интеграции или пользовательского интерфейса! Но не в папке test , в которую мы пишем тестовые случаи jUnit!

Заранее спасибо.

Пожалуйста, обратитесь к сборке. файл Gradle:

apply plugin: 'com.android.application'

    android {
    compileSdkVersion 28
    defaultConfig {
    applicationId "com.test.login"
    minSdkVersion 19
    targetSdkVersion 28
    versionCode 2
    versionName "1.1"
    multiDexEnabled true
    testInstrumentationRunner 
    "android.support.test.runner.AndroidJUnitRunner"
}

dataBinding {
    enabled = true
}

testOptions {
    unitTests.returnDefaultValues = true
}

buildTypes {
    release {
        minifyEnabled false
        proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
    }
}

}

dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
def design = "28.0.0"
implementation "com.android.support:appcompat-v7:$design"
implementation "com.android.support:design:$design"
implementation "com.android.support:recyclerview-v7:$design"

implementation 'com.android.support.constraint:constraint-layout:1.1.3'
implementation 'com.android.support:support-v4:28.0.0'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'

androidTestImplementation 'android.arch.core:core-testing:1.1.1'

implementation 'io.reactivex.rxjava2:rxjava:2.1.9'
implementation 'io.reactivex.rxjava2:rxandroid:2.0.2'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test:rules:1.0.2'
androidTestImplementation 'com.squareup.retrofit2:retrofit-mock:2.0.0'
implementation 'com.squareup.okhttp3:mockwebserver:3.8.1'
androidTestImplementation 'com.android.support.test.espresso:espresso-intents:3.0.2'
implementation 'com.jakewharton:butterknife:8.8.1'
annotationProcessor 'com.jakewharton:butterknife-compiler:8.8.1'

def daggerVer = 2.16
implementation "com.google.dagger:dagger:$daggerVer"
annotationProcessor "com.google.dagger:dagger-compiler:$daggerVer"
compileOnly 'javax.annotation:jsr250-api:1.0'
implementation 'javax.inject:javax.inject:1'

implementation 'com.squareup.retrofit2:retrofit:2.4.0'
implementation 'com.squareup.okhttp3:logging-interceptor:3.9.1'
implementation 'com.squareup.retrofit2:converter-gson:2.3.0'

//implementation 'com.google.android.material:material:1.0.0'

def lifeCycle = "1.1.1"
implementation "android.arch.lifecycle:extensions:$lifeCycle"
/*implementation "android.arch.lifecycle:runtime:$lifeCycle"
annotationProcessor "android.arch.lifecycle:compiler:$lifeCycle"*/
implementation "android.arch.persistence.room:runtime:$lifeCycle"
implementation 'com.mikhaellopez:circularimageview:3.2.0'
annotationProcessor 
"android.arch.persistence.room:compiler:$lifeCycle"

implementation 'com.squareup.picasso:picasso:2.71828'
implementation 'com.android.support:multidex:1.0.3'

implementation 'commons-beanutils:commons-beanutils:1.9.3'
implementation 'org.mockito:mockito-core:2.23.4'
androidTestImplementation 'org.mockito:mockito-android:2.18.3'
}

importErrorScreenshot

...