Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cannot resolve symbol InstantTaskExecutorRule

I open example code BasicRxJavaSample (from this article Room+RxJava) The main thing is there:

@Rule public InstantTaskExecutorRule instantTaskExecutorRule =      new InstantTaskExecutorRule(); 

And BasicRxJavaSample is all ok. But I can not apply this in my test. That's what's going on:

Cannot resolve symbol InstantTaskExecutorRule

enter image description here

And manual import does not work:

enter image description here

My autocompletion works like this enter image description here

But should be so

enter image description here

My app build.gradle (full gradle here):

// tests testImplementation 'junit:junit:4.12' androidTestCompile "com.android.support:support-annotations:$supportVersion" testImplementation "android.arch.core:core-testing:$archVersion" // Test helpers for Room testImplementation "android.arch.persistence.room:testing:1.0.0" // https://github.com/mockito/mockito testImplementation 'org.mockito:mockito-core:2.13.0' androidTestImplementation 'org.mockito:mockito-android:2.13.0' // AndroidJUnitRunner and JUnit Rules androidTestImplementation 'com.android.support.test:rules:1.0.1' androidTestImplementation 'com.android.support.test:runner:1.0.1' // https://developer.android.com/topic/libraries/testing-support-library/packages.html androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1' androidTestCompile 'com.android.support.test.espresso:espresso-idling-resource:3.0.1' 
like image 296
tim4dev Avatar asked Jan 01 '18 11:01

tim4dev


2 Answers

Replace testImplementation by androidTestImplementation. So the tests on folder androidTest can have access to the library.

dependencies {     androidTestImplementation "androidx.arch.core:core-testing:2.1.0" } 

If you are not using androidx then use android.arch.core:core-testing:1.1.1

like image 157
Paulo Pereira Avatar answered Sep 19 '22 13:09

Paulo Pereira


I know it's late but I would like to add one thing to this accepted answer.

If you want to use,

@Rule public InstantTaskExecutorRule instantTaskExecutorRule =  new InstantTaskExecutorRule(); 

in your JUnit test case, i.e., in test folder then use following dependency, i.e, with testImplementation

dependencies { testImplementation "android.arch.core:core-testing:1.0.0" } 

If you want to use InstantTaskExecutorRule for your UI or integration test cases(androidTest folder), use androidTestImplementation. that is:

androidTestImplementation "android.arch.core:core-testing:1.0.0"

And if you want to add for both, use androidTestImplementation & testImplementation that is:

androidTestImplementation "android.arch.core:core-testing:1.0.0"

testImplementation "android.arch.core:core-testing:1.0.0"

For Android-X use below dependency:

androidTestImplementation 'androidx.arch.core:core-testing:2.0.0'

OR

testImplementation 'androidx.arch.core:core-testing:2.0.0'

like image 29
Kavita_p Avatar answered Sep 16 '22 13:09

Kavita_p