在执行测试之前如何让gradlew卸载app?

问题描述 投票:0回答:2

在执行this solution测试之前,我使用uninstall来配置我的Android Studio,以及前一个应用程序的Espresso

所以,在Run -> Edit Configurations -> Before launch然后添加:app:uninstallAll所以,当我从AS运行我的测试用例时,我只选择配置,它运行良好。

enter image description here

我使用./gradlew connectedAndroidTest从命令行执行Espresso测试。但是,我想知道,

在执行测试之前,如何让gradle的命令行卸载以前的版本?

android gradle android-gradle android-espresso gradlew
2个回答
0
投票

您可以使用adb卸载以前的版本示例:

unistall old apk

adb -s $device uninstall ${packageName}.debug

uninstall test

adb -s $device uninstall "com.bookings.test"

device - connected device packageName - 应用程序的包名称。

希望这可以帮助 :)


0
投票

你不能问Gradle的命令行 - 但是Gradle可以询问命令行提示符。

基于这个答案here,可以轻松创建所需的应用程序卸载Exec任务:

task uninstallApp(type: Exec) {
    def uninstallCommand = ['adb', 'shell', 'pm', 'uninstall', 'com.acme.coyote']
    commandLine uninstallCommand
}

可以使用task.finalizedBytask.dependsOn添加此任务。

我也看到了我的answer,它解释了如何处理共享偏好......

因为从备份恢复这些偏好时;它没有全新安装。

最新问题
© www.soinside.com 2019 - 2025. All rights reserved.