我正在尝试使用我的SQLiteOpenHelper对象在Android Studio中针对我的应用数据库编写junit测试.每次遇到insert方法我都会得到一个NullPointerException.我在使用getContext()和我设置的mockContext之间来回走动,但没有骰子.我启动并运行了我的模拟器.有人可以告诉我我做错了什么吗?
public class LocationDatabaseHelperTest extends AndroidTestCase {
private SQLiteDatabase testDB;
private SQLiteDatabase readDB;
private LocationDatabaseHelper dbh;
private RenamingDelegatingContext mockContext;
private ContentValues cv;
/**
*Sets up a mock context to initialize the
* LocationDatabaseHelper object.
* @throws Exception
*/
public void setUp() throws Exception {
super.setUp();
final String prefix = "test";
mockContext = new RenamingDelegatingContext(getContext(),prefix);
dbh = new LocationDatabaseHelper(mockContext);
try {
testDB = dbh.getWritableDatabase();
} catch(Exception ex){
ex.printStackTrace();
}
readDB = dbh.getReadableDatabase();
cv = new ContentValues();
}
/**
*Tests that …Run Code Online (Sandbox Code Playgroud)