Skip to content Skip to sidebar Skip to footer

Android Studio 2.1: Error: Package Org.junit Does Not Exist

Update: Its a bug and it's been reported, please star: https://code.google.com/p/android/issues/detail?id=209832&thanks=209832&ts=1463161330 I'm setting up unit testing on

Solution 1:

I changed TestCompile to androidTestCompile and it's worked without problems.

testCompile 'junit:junit:4.12'

to

androidTestCompile 'junit:junit:4.12'

Solution 2:

add this dependency to solve your issue

testCompile 'junit:junit:4.12'compile'junit:junit:4.12'

Solution 3:

Solution 4:

Some things you should check -

  • Do you have unit test and debug selected under build variants?
  • Is your working directory set to $MODULE_DIR$ in Run/Debug configurations for the unit test?
  • Did you create the test by selecting the class you wish to test, going to Navigate -> Test and having Android Studio construct the test class for you?

Solution 5:

My tests are in src/test/java folder and adding test.setRoot('test') to sourceSets worked for me.

sourceSets {
    test.setRoot('test')
}

Post a Comment for "Android Studio 2.1: Error: Package Org.junit Does Not Exist"