androidunit-testingandroid-gradle-pluginrobolectricrobolectric-gradle-plugin

"RobolectricTestRunner.class" not recognized in Android Studio


I'm trying to use Robolectric to run unit tests but the Android Studio is not recognizing the class on:

@RunWith(RobolectricTestRunner.class)

Details:

classpath 'com.android.tools.build:gradle:3.0.0'

And I'm importing dependency:

testImplementation "org.robolectric:robolectric:3.5.1"

And:

android {
    testOptions {
        unitTests {
            includeAndroidResources = true
        }
    }
}

It simply does not appear option to import the class. Should I add any more dependencies I'm forgetting?

Error:

 error: package org.robolectric does not exist
 error: package org.robolectric does not exist
 error: package org.robolectric.shadows does not exist
 error: cannot find symbol class RobolectricTestRunner
 error: cannot find symbol variable Robolectric
 error: cannot find symbol variable ShadowApplication

Solution

  • I solved the issue just by putting the test class inside the src \ test folder instead of putting it in thesrc \ androidTest folder