我一直在研究一个UIAutomator示例项目。我使用AndroidX测试库创建了新的测试用例。
我能够从命令行构建并运行测试用例。但是当我尝试从Android Studio打开应用程序时,我发现大部分类没有正确导入。例如:
import androidx.test.uiautomator.UiObject2;
import org.junit.Before;
以上两个导入未被导入。同样的错误在许多类中都出现,除了android.content.Context、android.content.Intent等。
有人能否解释一下。我能够从命令行正确地执行测试用例,但无法从Android Studio中正确地执行它们。
我已经重启了电脑/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示例代码所提供的方式进行操作的,但不确定我是否遗漏了什么。