【发布时间】:2019-05-05 14:33:34
【问题描述】:
我一直在研究 UIAutomator 示例项目。我已经使用 AndroidX 测试库创建了新的测试用例。
我能够从命令行构建、运行测试用例。但是当我尝试从 Android Studio 打开应用程序时,我可以看到大多数类都没有正确导入。例如,
import androidx.test.uiautomator.UiObject2;
import org.junit.Before;
以上两个导入显示为未导入。同样,除了 android.content.Context、android.content.Intent 等,许多类都显示相同的错误,
有人可以对此有所了解。我能够从命令行正确执行测试用例,但无法从 Android Studio 正确执行。
我已经重启了PC/Studio,清除了缓存,问题依然存在。
下面是我在 app/build.gradle 中添加的依赖。
androidTestImplementation 'androidx.test.uiautomator:uiautomator:2.2.0'
androidTestImplementation 'androidx.test:core:1.0.0'
androidTestImplementation 'androidx.test.ext:junit:1.0.0'
androidTestImplementation 'androidx.test:runner:1.1.0'
androidTestImplementation 'junit:junit:4.12'
在 gradle.properties 中添加以下代码
android.useAndroidX=true
android.enableJetifier=true
我几乎遵循了从 android-testing-master/ui/uiautomator 示例代码中得到的相同内容,但不确定我缺少什么。
【问题讨论】:
-
重建您的项目,如果问题仍然存在,请使用 gradle 文件同步项目。
标签: android android-studio instrumentation android-uiautomator junit-runner