我一直在做示例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/ui中获得的示例代码,不确定我遗漏了什么。
发布于 2019-08-14 17:49:13
我也遇到了同样的问题(Android Studio 3.4.2),uiautomator是红色的:
import androidx.test.uiautomator.UiDevice“清理项目”和“重建项目”没有帮助,甚至无效缓存。但选择另一个构建变体对我很有帮助。
https://stackoverflow.com/questions/53608315
复制相似问题