public int delete(int id)
{
SQLiteDatabase db = this.getWritableDatabase();
String where = "id = ?";
String[] whereValue =
{ Integer.toString(id) };
return db.delete(TABLE_NAME, where, whereValue);
}
测试类:
public class Test extends AndroidTestCase
{
Sqlitehelper dbHelper;
SQLiteDatabase db;
@Override
protected void setUp() throws Exception
{
super.setUp();
dbHelper=new Sqlitehelper(getContext(), "database.db");
db=dbHelper.getReadableDatabase();
}
private void deleteTest()
{
Assert.assertEquals(1, dbHelper.delete(1));
}
4.在test所在包上右键,run as->android junit test,将Junit的视图在 window->show view 中找出来,如果没错,junit显示绿色,反之红色