Android Studio集成测试无法解析符号AndroidJUnit4 [英] Android Studio Integration test cannot resolve symbol 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
- 使用向导创建新的Android应用
-
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屋!