我已经看到类似问题的部分答案,但实际上并没有解决问题。我已经把这个简化为一个最小的应用程序来演示这个问题。Android Studio集成测试无法解析符号AndroidJUnit4
我使用过Android Studio(V2.2.1) 的最新版本,我有以下SDK的安装:
- Android SDK工具v25.1.6
- 的Android SDK平台的工具V23。 1
- Android SDK中内建工具v23.0.3
支持Android库V32
defaultConfig补充下:
- testInstrumentationRunner“android.support.test.runner
- 使用向导每
更新的build.gradle(应用)创建新的Android应用程序。 AndroidJUnitRunner“
在依赖项下添加
- androidTestCompile 'com.android.support:support-annotations:23.0.1' < - 更改为23.4.0,以配合新生成的应用程序
- androidTestCompile“com.android.support.test:亚军:0.4.1'
- androidTestCompile 'com.android.support.test:规则:0.4.1'
- androidTestCompile 'com.android.support:support-annotations:23.0.1' < - 更改为23.4.0,以配合新生成的应用程序
没有项目同步同步g^https://developer.android.com/training/testing/unit-testing/instrumented-unit-tests.html
:每ExampleIntegrationTest.java(旁边ExampleUnitTest.java)
在新的文件,创建集成测试 - radle
在 “测试” 包增加新的测试文件
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;
如果我输入导入语句,我可以使用弹出建议:
- 导入android。 - 它显示“作为选项支持”
- 导入android.support。 - 它显示“测试”作为选项
- 导入android.support.test。 - 现在,它只能说明“规定”作为一个选项
后,我创建应用程序,我要确保它使用“调试”变种
这是非常添油加醋。据我可以告诉这应该工作,但支持库出于某种原因不能正确导入。通过将测试到
- /应用/ SRC/androidTest指南代替
- /应用/ SRC /测试目录是用于单元测试仅
的
你有没有得到过这个?我以前见过它,它消失了,我有一种感觉,它与我自己的更新依赖关系有关。因此,看到'尝试做正确的方式,并使用androidTest文件夹' –