Last active
December 29, 2016 09:58
-
-
Save AntonioDiaz/48b28d3d6f4a976f7e08e8d33b08fe83 to your computer and use it in GitHub Desktop.
Testing db in android app.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.example.android.sunshine.app.data; | |
import android.content.ContentValues; | |
import android.database.Cursor; | |
import android.database.sqlite.SQLiteDatabase; | |
import android.test.AndroidTestCase; | |
import java.util.HashSet; | |
public class TestDb extends AndroidTestCase { | |
public static final String LOG_TAG = TestDb.class.getSimpleName(); | |
// Since we want each test to start with a clean slate | |
void deleteTheDatabase() { | |
mContext.deleteDatabase(WeatherDbHelper.DATABASE_NAME); | |
} | |
public void setUp() { | |
deleteTheDatabase(); | |
} | |
public void testCreateDb() throws Throwable { .. } | |
public void testLocationTable() { .. } | |
public void testUpdateLocationAux(){ | |
WeatherDbHelper weatherDbHelper = new WeatherDbHelper(this.mContext); | |
SQLiteDatabase db = weatherDbHelper.getWritableDatabase(); | |
/** insert value */ | |
ContentValues values = TestUtilities.createNorthPoleLocationValues(); | |
long newId = db.insert(LocationEntry.TABLE_NAME, null, values); | |
String whereClause = "_id = ? "; | |
String [] whereArgs = new String[] {Long.toString(newId)}; | |
Cursor cursorAux = db.query(WeatherContract.LocationEntry.TABLE_NAME, null, whereClause, whereArgs, null, null, null); | |
assertEquals("Testing insert...", 1, cursorAux.getCount()); | |
TestUtilities.validateCursor("testUpdateLocation. Error validating location entry update.", cursorAux, values); | |
cursorAux.close(); | |
db.close(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment