Attempted to use AndroidJUnit4 with standard JUnit runner and delegate runner 'org.robolectric.RobolectricTestRunner'could not be loaded

I see you're using AndroidX. Make sure you are using the correct import. I ran in to this exact issue today and realized I was still using the old import android.support.test.runner.AndroidJUnit4; when I should have been using import androidx.test.runner.AndroidJUnit4;

This fixed the the error for me.


I added the dependency to my gradle file and it can find Roboelectric now

    testImplementation 'org.robolectric:robolectric:4.0'

Hope it helps


update for kotlin. Make sure that all @Rule annotations are in form of @get:Rule - that was a problem in my case.