Cannot resolve symbol InstantTaskExecutorRule

android livedata unit test
method getmainlooper in android.os.looper not mocked
method getmainlooper in android.os.looper not mocked livedata
livedata unit test observe
com android support test runner:1.0 2
getorawaitvalue
unit testing android studio
espresso-contrib

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

And manual import does not work:

My autocompletion works like this

But should be so

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'

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

InstantTaskExecutorRule, The activity under test is launched before each test annotated with @Test and before any method annotated with @Before . It's terminated after  However most of the Features I want to use are working but I got confused after seeing lots of "Cannot resolve symbol" Messages after running "Find Code Issues". The code is working fine an most of the errors looks like ReSharper Bugs or I do not understand what ReSharper wants from me.

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'

JUnit4 rules with AndroidX Test, inside spek to swaps the background executor. I am trying to test MutableLiveData, but running into java.lang.RuntimeException: Method  How to fix cannot resolve symbol AppCompatActivity - Android Studio - Duration: 4:32. Real Tech 33,821 views. 4:32. Cannot Resolve R Symbol - Android Studio 2.1 - Tutorial LATEST - Duration: 5:38.

for androidX migration, add

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

Android LiveData testing @Rule InstantTaskExecutorRule · Issue , InstantTaskExecutorRule is a JUnit Test Rule that swaps the the before method and then checking if we are getting an empty note list or not  Recently I face this cannot resolve symbol r issue, I tried all the ways mentioned in this tutorial. In the last, I did update my Android studio and the problem was solved. In the last, I did update my Android studio and the problem was solved.

Please put this two dependencies in your gradle file,

dependencies {

    // Test helpers for LiveData
    testImplementation "android.arch.core:core-testing:1.0.0"

    // Test helpers for Room
    testImplementation "android.arch.persistence.room:testing:1.0.0"
}

Further information please go through this link, Android Architecture components integration guide

Testing the Un-Testable With Android Architecture Components , InstantTaskExecutorRule import android.arch.persistence.room. I don't seem to be doing anything incorrectly, but for the life of me, I can't figure out to resolve your dependencies might be the most sensible thing in the long term. You can get an injected activity that you are testing on by calling its getActivity() method. In the web and server control projects, all references to System.Web and System.ComponentModel are highlighted as Cannot Resolve Symbol 'Web' and Cannot Resolve Symbol 'ComponentModel'. All the attributes on my server controls also are not resolved because of that, as well as symbols like Page and DataList.

I think that there is a conflict in some of the linked libraries. I got around this, I used blockingGet() and blockingFirst().

and, in the end, I used https://developer.android.com/training/testing/junit-runner.html#using-android-test-orchestrator

androidTestUtil 'com.android.support.test:orchestrator:1.0.1'

this is what you need!

Unresolved reference: testing, Cannot resolve symbol InstantTaskExecutorRule · android unit-testing junit4 rx-​java2 asked Jan 1 '18 at 11:06. stackoverflow.com · 7 votes  In every instance in all of my classes where I reference R.id.something, the R is in red and it says "cannot resolve symbol R". Also every time there is R.layout.something it is underlined in red and says "cannot resolve method setContentView(?)". The project always builds fine.

User tim4dev, Top network posts. 31 Cannot resolve symbol InstantTaskExecutorRule · 5 Android JUnit test with Context.getApplicationContext() · View more network posts →  5 Cara Mengatasi Cannot Resolve Symbol R pada Android Studio October 11, 2019 October 11, 2019 Guntoro Android Studio , Mobile Development Pada saat awal-awal belajar membuat aplikasi dengan Android Studio , seringkali saya menemukan masalah Cannot Resolve Symbol R ketika sedang melakukan pengcodingan di file java contohnya MainActivity.java.

User Kavita_p, On my code I have to import this: com.google.common.base.Preconditions.checkState, the IDE says: Cannot resolve symbol 'google' and in some forums users says that the solution is modify the pom.xml

Here we discuss about how to deal with “cannot resolve symbol R” error in an Android Project. Normally this error occur when there is an error in xml file or your

Comments
  • I have made the above changes but this solution didn't work in my case. Is there any other possibility?
  • This shoild be the best answer
  • Thanks for pointing out @Kavita_p .... Android is mostly crazy and not developer friendly. testImplementation and androidTestImplementation should be defined if system needs to have dependency in Instrumentation test and Unit test... Wondering, when Google will make all these as developer friendly..!!!! I found IOS development much more developer friendly... these thinks Really Sucks....
  • But if you use implementation, this library code will be present on your release APK. Which is not necessary or correct. If you want use on both, you should use both androidTestImplementation and testImplementation.
  • Hi, @PauloPereira thanks for your input. Yes, you are right about including these libs in release APK. I will update my answer as well.
  • Latest version info can be found here - developer.android.com/jetpack/androidx/releases/lifecycle