Android Studio 2.1: error: package org.junit does not exist

前端 未结 7 1573
别那么骄傲
别那么骄傲 2020-12-29 23:58

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

<
相关标签:
7条回答
  • 2020-12-30 00:30

    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?
    0 讨论(0)
  • 2020-12-30 00:42

    It looks like Gradle is not doing it's job.

    Manually adding the jars fixed the problem.

    0 讨论(0)
  • 2020-12-30 00:46

    Download (junit-4.12.jar) from https://github.com/junit-team/junit4/wiki/Download-and-Install and copy it in your libs folder:(yourProjectFolder/app/libs)

    and then in build.gradle(Module: app) use this codes:

    dependencies {
    ...
    compile files('libs/junit-4.12.jar')
    ...
    }
    

    then rebuild your project.

    0 讨论(0)
  • 2020-12-30 00:47

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

    testCompile 'junit:junit:4.12'
    

    to

    androidTestCompile 'junit:junit:4.12'
    
    0 讨论(0)
  • 2020-12-30 00:47

    add this dependency to solve your issue

    testCompile 'junit:junit:4.12'
    compile 'junit:junit:4.12'
    
    0 讨论(0)
  • 2020-12-30 00:52

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

    sourceSets {
        test.setRoot('test')
    }
    
    0 讨论(0)
提交回复
热议问题