【问题标题】:@RunWith annotation not found in Android studio在 Android Studio 中找不到 @RunWith 注释
【发布时间】:2020-01-31 05:45:59
【问题描述】:

我和 android studio 项目具有以下与测试相关的依赖项:

implementation fileTree(include: ['*.jar'], dir: 'libs')
implementation fileTree(include: ['*.aar'], dir: 'libs')

// Core library
androidTestImplementation 'androidx.test:core:1.1.0'

// AndroidJUnitRunner and JUnit Rules
androidTestImplementation 'androidx.test:runner:1.1.1'
androidTestImplementation 'androidx.test:rules:1.1.1'

// Assertions
androidTestImplementation 'androidx.test.ext:junit:1.1.0'
androidTestImplementation 'androidx.test.ext:truth:1.1.0'
androidTestImplementation 'com.google.truth:truth:0.42'

// Espresso dependencies
androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.1'
androidTestImplementation 'androidx.test.espresso:espresso-contrib:3.1.1'
androidTestImplementation 'androidx.test.espresso:espresso-intents:3.1.1'
androidTestImplementation 'androidx.test.espresso:espresso-accessibility:3.1.1'
androidTestImplementation 'androidx.test.espresso:espresso-web:3.1.1'
androidTestImplementation 'androidx.test.espresso.idling:idling-concurrent:3.1.1'

// The following Espresso dependency can be either "implementation"
// or "androidTestImplementation", depending on whether you want the
// dependency to appear on your APK's compile classpath or the test APK
// classpath.
androidTestImplementation 'androidx.test.espresso:espresso-idling-resource:3.1.1'

Android Studio 仍然无法导入 @RunWith 注解。我在使用 andoridx 的 API 28 设计库时遇到了同样的问题。我相信 androidx 仍然很烂,即使它被要求开发人员使用 androidx 库!

我的 gradle 工具版本是 '3.3.2' 而 android studio 稳定版是 3.3.2

【问题讨论】:

    标签: android junit android-espresso androidx


    【解决方案1】:

    您确定您使用的是正确的构建变体吗?我遇到了同样的问题,切换到 debug 构建变体让我可以正确添加导入

    【讨论】:

      【解决方案2】:

      将此依赖项添加到您的应用模块的build.gradle

          testImplementation 'junit:junit:4.12'
          androidTestImplementation 'junit:junit:4.12'
      

      【讨论】:

        【解决方案3】:

        添加这些依赖项:

        testImplementation 'junit:junit:4.12'
        androidTestImplementation 'junit:junit:4.12'
        

        并确保您在 androidTest 包中并使用 debug Build Variant

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2017-04-12
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2017-11-14
          • 1970-01-01
          相关资源
          最近更新 更多