Skip to content

Instantly share code, notes, and snippets.

@nking
Created September 1, 2011 03:13

Revisions

  1. nking revised this gist Sep 1, 2011. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions gistfile1.txt
    Original file line number Diff line number Diff line change
    @@ -17,8 +17,8 @@ expected db location:
    /data/data/your.android.package.name/files/yourprojectname_version.db

    Then in your test class which extends ProviderTestCase2<CProvider>, have a test
    method to start asserting that using yourprojectname_version.db with your content
    provider succeeds and assert your methods.
    method to assert that yourprojectname_version.db is updated in your ContentProvider
    (method onUpgrade) and assert your methods...

    String dbPath =
    "/data/data/your.android.package.name/files/yourprojectname_version.db";
  2. nking revised this gist Sep 1, 2011. 1 changed file with 4 additions and 2 deletions.
    6 changes: 4 additions & 2 deletions gistfile1.txt
    Original file line number Diff line number Diff line change
    @@ -2,7 +2,8 @@ If you want to test upgrades of your database schemas against new releases that
    included database version changes:

    To save your database,
    adb shell pull /data/data/your.android.package.name/databases/yourprojectname.db /yourprojectcvsdir/databases/yourprojectname_version.db
    adb shell pull /data/data/your.android.package.name/databases/yourprojectname.db \
    /yourprojectcvsdir/databases/yourprojectname_version.db

    If you're using a ContentProvider such as given by the Android example
    http://developer.android.com/resources/samples/NotePad/src/com/example/android/notepad/NotePadProvider.html
    @@ -12,7 +13,8 @@ below, the extended SQLiteOpenHelper is in a separate class.
    Before you test your ContentProvider, run a target to install the older version
    database in the adb virtual shell with a location that doesn't conflict with the
    expected db location:
    adb shell push /yourprojectcvsdir/databases/yourprojectname_version.db /data/data/your.android.package.name/files/yourprojectname_version.db
    adb shell push /yourprojectcvsdir/databases/yourprojectname_version.db \
    /data/data/your.android.package.name/files/yourprojectname_version.db

    Then in your test class which extends ProviderTestCase2<CProvider>, have a test
    method to start asserting that using yourprojectname_version.db with your content
  3. nking revised this gist Sep 1, 2011. 1 changed file with 14 additions and 10 deletions.
    24 changes: 14 additions & 10 deletions gistfile1.txt
    Original file line number Diff line number Diff line change
    @@ -1,22 +1,25 @@

    If you want to test upgrades of your database schemas against new releases that have included database version changes:
    If you want to test upgrades of your database schemas against new releases that have
    included database version changes:

    To save your database,
    adb shell pull /data/data/your.android.package.name/databases/yourprojectname.db /yourprojectcvsdir/databases/yourprojectname_version.db

    If you're using a ContentProvider such as given by the Android example
    http://developer.android.com/resources/samples/NotePad/src/com/example/android/notepad/NotePadProvider.html
    make the methods accepting SQLiteDatabase arguments accessible. In the example below,
    the extended SQLiteOpenHelper is in a separate class.
    make the methods accepting SQLiteDatabase arguments accessible. In the example
    below, the extended SQLiteOpenHelper is in a separate class.

    Before you test your ContentProvider, run a target to install the older version database
    in the adb virtual shell with a location that doesn't conflict with the expected db location:
    Before you test your ContentProvider, run a target to install the older version
    database in the adb virtual shell with a location that doesn't conflict with the
    expected db location:
    adb shell push /yourprojectcvsdir/databases/yourprojectname_version.db /data/data/your.android.package.name/files/yourprojectname_version.db

    Then in your test class which extends ProviderTestCase2<CProvider>, have a test method
    to start asserting that using yourprojectname_version.db with your content provider succeeds and assert your methods.
    Then in your test class which extends ProviderTestCase2<CProvider>, have a test
    method to start asserting that using yourprojectname_version.db with your content
    provider succeeds and assert your methods.

    String dbPath = "/data/data/your.android.package.name/files/yourprojectname_version.db";
    String dbPath =
    "/data/data/your.android.package.name/files/yourprojectname_version.db";

    SQLiteDatabase db = null;

    @@ -28,7 +31,8 @@ to start asserting that using yourprojectname_version.db with your content provi

    CProvider cProvider = getProvider();

    Collection<YourObjects> list = cProvider.getObjects(db); // a wrapper to method that iterates over cursor to populate objects, for example
    // a wrapper to method that iterates over cursor to populate objects, for example
    Collection<YourObjects> list = cProvider.getObjects(db);

    assertNotNull(list);

  4. nking created this gist Sep 1, 2011.
    44 changes: 44 additions & 0 deletions gistfile1.txt
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,44 @@

    If you want to test upgrades of your database schemas against new releases that have included database version changes:

    To save your database,
    adb shell pull /data/data/your.android.package.name/databases/yourprojectname.db /yourprojectcvsdir/databases/yourprojectname_version.db

    If you're using a ContentProvider such as given by the Android example
    http://developer.android.com/resources/samples/NotePad/src/com/example/android/notepad/NotePadProvider.html
    make the methods accepting SQLiteDatabase arguments accessible. In the example below,
    the extended SQLiteOpenHelper is in a separate class.

    Before you test your ContentProvider, run a target to install the older version database
    in the adb virtual shell with a location that doesn't conflict with the expected db location:
    adb shell push /yourprojectcvsdir/databases/yourprojectname_version.db /data/data/your.android.package.name/files/yourprojectname_version.db

    Then in your test class which extends ProviderTestCase2<CProvider>, have a test method
    to start asserting that using yourprojectname_version.db with your content provider succeeds and assert your methods.

    String dbPath = "/data/data/your.android.package.name/files/yourprojectname_version.db";

    SQLiteDatabase db = null;

    try {

    ProviderDBHelper dbHelper = new ProviderDBHelper(getContext(), dbPath, version);

    db = dbHelper.getWritableDatabase();

    CProvider cProvider = getProvider();

    Collection<YourObjects> list = cProvider.getObjects(db); // a wrapper to method that iterates over cursor to populate objects, for example

    assertNotNull(list);

    assertTrue(list.size() > 0);

    } catch (Throwable t) {
    fail(t.getMessage());
    }