title: Android SQLite Database Unit Testing
body: <p>I'm new to android app development and I just made a note app. I want to do unit tests for the insertNote, readNote and updateNote methods for the database. How do I go about this? This is the code for my database. 
  Thanks.</p>
  
  <pre><code>public class  DatabaseManager extends SQLiteOpenHelper {
  
  
  public static final String Database_Name = "Notes Database";
  public static final String Table_Name = "notes";
  
  public static final String Column_id = "textId";
  public static final String Column_title = "textTitle";
  public static final String Column_body = "textBody";
  
  public DatabaseManager(Context context){
      super(context, Database_Name, null, 1);
  }
  
  @Override
  public void onCreate(SQLiteDatabase db){
      db.execSQL("CREATE TABLE " + Table_Name + " (" + Column_id +
              " INTEGER PRIMARY KEY AUTOINCREMENT, " + Column_title +
              " TEXT, " + Column_body + " TEXT)");
  }
  
  @Override
  public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion){
      db.execSQL("DROP TABLE IF EXISTS" + Table_Name);
      onCreate(db);
  }
  
  public void insertNote(Note note){
      SQLiteDatabase db = this.getWritableDatabase();
  
      ContentValues values = new ContentValues();
      values.put(Column_title, note.getTextTitle());
      values.put(Column_body, note.getTextBody());
  
      boolean result = db.insert(Table_Name, null, values) &gt; 0;
      if (result == true)
          Log.d("Create", "Data Has Been Saved");
      db.close();
  }
  
  public Cursor readNote(int id){
      SQLiteDatabase db = this.getReadableDatabase();
  
      Cursor cursor = db.rawQuery("SELECT * FROM " + Table_Name + " WHERE _ROWID_ = " + id, null);
  
      if (cursor != null){
          cursor.moveToFirst();
      }
  
      Note myNote = new Note();
      myNote.textId = cursor.getInt(cursor.getColumnIndex(Column_id));
      myNote.textTitle = cursor.getString(cursor.getColumnIndex(Column_title));
  
      return cursor;
  }
  
  public ArrayList&lt;String&gt; getNoteList(){
      ArrayList&lt;String&gt; noteList =  new ArrayList&lt;&gt;();
      SQLiteDatabase db = this.getReadableDatabase();
      Cursor cursor = db.rawQuery("SELECT * FROM " + Table_Name, null);
      cursor.moveToFirst();
  
      if (cursor.moveToFirst()){
          do{
              //noteList.add(cursor.getInt(cursor.getColumnIndex(Column_id)));
              noteList.add(cursor.getString(cursor.getColumnIndex(Column_title)));
          }
          while (cursor.moveToNext());
      }
  
      return noteList;
  }
  
  public int updateNote(Note note){
      SQLiteDatabase db = this.getWritableDatabase();
  
      ContentValues values = new ContentValues();
      values.put("textTitle", note.getTextTitle());
      values.put("textBody", note.getTextBody());
  
      int update = db.update(Table_Name, values, Column_id + " = ?", new String[]{Integer.toString(note.getTextId())});
      return update;
  }
  
  public Integer deleteNote(int id){
      SQLiteDatabase db = this.getWritableDatabase();
     return db.delete(Table_Name, Column_id + " = ?", new String[]{Integer.toString(id)} );
  }
  
  public int getCount(){
      SQLiteDatabase db = this.getReadableDatabase();
      Cursor cursor = db.rawQuery("SELECT * FROM " + Table_Name, null);
      cursor.close();
  
      return cursor.getCount();
  }
  </code></pre>
  
  <p>}</p>