简体   繁体   中英

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. 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.

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.

No, there's no way. But there's an easy way to uninstall it:

  • Go to the menu, where you see the app
  • Hit the menu button, click "Manage Apps"
  • Click your app
  • It will ask you if you really want to uninstall it
  • Click "Yes" or "Uninstall" button. It will be uninstalled with all the data.

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.

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.

@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.

If the app data is the problem, you could just clear it rather than performing an uninstall. This link should help.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM