[英]How can I automatically uninstall the app from the emulator after running the Android unit test
I am using Eclipse ADT to test an Android App. 我正在使用Eclipse ADT测试Android应用程序。 However, after I execute the test suite once, the emulator will have the app installed. 但是,一次执行测试套件后,模拟器将安装该应用程序。 I need to remove it from the emulator since the test will fail next time if the app is already installed on the emulator (due to some stored data). 我需要将其从模拟器中删除,因为如果该应用程序已经安装在模拟器上(由于存储了一些数据),则下次测试将失败。
I tried to search a way to start a clean emulator every time I run the test suite, but has no luck so far. 每次运行测试套件时,我都试图寻找一种方法来启动一个干净的模拟器,但是到目前为止还没有运气。
Any suggestions? 有什么建议么?
Thanks. 谢谢。
BTW, I am using Robotium package. 顺便说一句,我正在使用Robotium软件包。
Quick solution: 快速解决方案:
adb -e uninstall your.test.package.name
Cleaner solution: 清洁解决方案:
Back up a known good userdata-qemu.img
emulator disk image and restore it before launching the emulator for new test run. 在启动模拟器进行新的测试运行之前,请备份一个已知的良好的userdata-qemu.img
仿真器磁盘映像,并将其还原。
No, there's no way. 不,没有办法。 But there's an easy way to uninstall it: 但是有一种简单的方法可以卸载它:
Hope this helps. 希望这可以帮助。
If your data is in a SQLite database you can change the database version to a higher version than the actual version. 如果您的数据在SQLite数据库中,则可以将数据库版本更改为比实际版本更高的版本。
private static final int DATABASE_VERSION = 2; //in the class that extends SQLiteOpenHelper
This will call the onUpgrade function, there you can delete the tables and create them again. 这将调用onUpgrade函数,您可以在其中删除表并再次创建它们。
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
//erase table
db.execSQL("DROP TABLE IF EXISTS " + MY_TABLE);
//create again
onCreate(db);
}
If you're not using SQLite just overwrite the files. 如果您不使用SQLite,则只需覆盖文件即可。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.