Android Studio集成测试无法解析符号AndroidJUnit4 [英] Android Studio Integration test cannot resolve symbol AndroidJUnit4

查看:548
本文介绍了Android Studio集成测试无法解析符号AndroidJUnit4的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经看到过类似问题的部分答案,但是从来没有真正解决过这个问题的答案.我将其简化为一个最小的应用程序以演示该问题.

I've seen partial answers to similiar issues but never one that actually solved the problem. I've boiled this down to a minimal app to demonstrate the issue.

我正在使用最新版本的Android Studio(V2.2.1) 我已安装以下SDK:

I'm using the most current version of Android Studio (V2.2.1) I have the following SDK's installed:

  • Android SDK工具v25.1.6
  • Android SDK平台工具v23.1
  • Android SDK Build-tools v23.0.3
  • Android支持存储库v32

  • Android SDK Tools v25.1.6
  • Android SDK Platform-tools v23.1
  • Android SDK Build-tools v23.0.3
  • Android Support repository v32

  1. 使用向导创建新的Android应用
  2. 更新后的build.gradle(应用程序),每个版本:

  3. 在defaultConfig下添加:

    • Added under defaultConfig:

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

    在依赖项下添加了

    Added under dependencies

    • androidTestCompile'c​​om.android.support:support-annotations:23.0.1'<-更改为23.4.0以匹配新生成的应用程序
    • androidTestCompile'c​​om.android.support.test:runner:0.4.1'
    • androidTestCompile'c​​om.android.support.test:rules:0.4.1'

    是否已同步项目以同步Gradle

    Did project sync to sync Gradle

    在测试"包下,添加新的测试文件-ExampleIntegrationTest.java(在ExampleUnitTest.java旁边)

    Under the "test" package add new test file - ExampleIntegrationTest.java (right next to ExampleUnitTest.java)

    在新文件中,根据以下内容创建集成测试:

    In the new file, created integration test per: https://developer.android.com/training/testing/unit-testing/instrumented-unit-tests.html

  4. import android.support.test.runner.AndroidJUnit4;
    import android.test.suitebuilder.annotation.SmallTest;
    
    import org.junit.runner.RunWith;
    
    
    @RunWith(AndroidJUnit4.class)
    @SmallTest
    public interface ExampleIntegrationTest {
    }
    


    这是问题所在-无法解析符号AndroidJUnit4 在线:import android.support.test.runner.AndroidJUnit4;


    This is where the problem comes up - cannot resolve symbol AndroidJUnit4 On the line: import android.support.test.runner.AndroidJUnit4;

    如果输入import语句,则可以使用弹出式建议:
    -导入android. -它显示支持作为选项"
    -导入android.support. -它显示测试"作为选项
    -导入android.support.test. -现在仅显示"rule"作为规则

    If I type the import statement I can use the popup suggestions:
    - import android. - It shows "support as option"
    - import android.support. - It shows "test" as an option
    - import android.support.test. - Now it only shows "rule" as a option

    创建应用后,请确保其使用的是调试"变体

    After I create the app I make sure it's using the "debug" variant

    这很漂亮,很干.据我所知,这应该可行,但是由于某种原因,支持库无法正确导入.

    This is pretty cut and dry. As far as I can tell this should work,, but the support library for some reason isn't getting imported correctly.

    推荐答案

    通过将测试添加到

    • /app/src/androidTest目录而不是
    • /app/src/test目录,仅用于单元测试

    或者,当您创建测试类时,通过在项目"树的"Android Instrumentation测试"标签中选择新的类来添加测试

    Or, when you create the test class, add the test by selecting new class when in "Android Instrumentation Tests" tab of the Project tree

    这篇关于Android Studio集成测试无法解析符号AndroidJUnit4的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆