我一直在研究示例 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 示例代码中获得的相同内容,不确定我缺少什么。
我也遇到了同样的问题(Android Studio 3.4.2),
uiautomator
是红色的:
import androidx.test.uiautomator.UiDevice
“清理项目”和“重建项目”没有帮助,甚至使缓存失效。但选择另一个构建变体对我有帮助。
因为
androidTestImplementation