Search code examples
androidjunit4android-testingandroid-instrumentation

jUnit not found in androidTest folder but found in test folder


I am writing instrumented tests in android but when I import jUnit (to use @RunWith annotation), it is not able to find jUnit but I am already using jUnit in unit tests (under test folder). I am not able to even start writing the tests.
Same thing is happening with AndroidJUnit4 class.

I have included this stuff in build.gradle :

testCompile brazilGradle.testbuild('junit')

androidTestCompile brazilGradle.testbuild('AndroidSupportTestPackage-rules')
androidTestCompile brazilGradle.testbuild('AndroidSupportTestPackage-runner')

I have also included this in defaultConfig :

testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"

How come it is working in one folder and not in another ?


Solution

  • The silly error on my part was that by Build Variant was set to debug and by changing it to release I was able to use dependencies not available to me earlier.
    If anyone cannot find this setting, this can be seen as a Build Varaint tab at the bottom left corner. Clicking on that should open a small panel containing the app module and the corresponding build variant. Clicking on that column should show the dropdown with release and debug and any other flavors if any.