請幫助。我被卡住了。有人會告訴我爲什麼我在JUnit測試中有AssertionFailedError。我不知道爲什麼SQLiteDatabase數據庫插入方法返回-1。SQLite數據庫插入返回-1
錯誤指向第50行:assertTrue(locationRowId!= -1);
public void testInsertReadDb() {
// Test data we're going to insert into the DB to see if it works.
String testLocationSetting = "99705";
String testCityName = "North Pole";
double testLatitude = 64.7488;
double testLongitude = -147.353;
// If there's an error in those massive SQL table creation Strings,
// errors will be thrown here when you try to get a writable database.
WeatherDbHelper dbHelper = new WeatherDbHelper(mContext);
SQLiteDatabase db = dbHelper.getWritableDatabase();
// Create a new map of values, where column names are the keys
ContentValues values = new ContentValues();
values.put(LocationEntry.COLUMN_LOCATION_SETTING, testLocationSetting);
values.put(LocationEntry.COLUMN_CITY_NAME, testCityName);
values.put(LocationEntry.COLUMN_COORD_LAT, testLatitude);
values.put(LocationEntry.COLUMN_COORD_LONG, testLongitude);
//long locationRowId;
long locationRowId = db.insert(LocationEntry.TABLE_NAME, null, values);
// Verify we got a row back.
assertTrue(locationRowId != -1);
Log.d(LOG_TAG, "New row id: " + locationRowId);
以下是錯誤:
Running tests
Test running started
junit.framework.AssertionFailedError
at com.example.krisemmanuel.sunshine.test.TestDb.testInsertReadDb(TestDb.java:50)
at java.lang.reflect.Method.invokeNative(Native Method)
at android.test.AndroidTestRunner.runTest(AndroidTestRunner.java:191)
at android.test.AndroidTestRunner.runTest(AndroidTestRunner.java:176)
at android.test.InstrumentationTestRunner.onStart(InstrumentationTestRunner.java:554)
at android.app.Instrumentation$InstrumentationThread.run(Instrumentation.java:1729)
Finish
以下是錯誤的屏幕: http://picpaste.com/debughelpplease-IuEAYaNu.png
和Android Studio項目文件夾: http://krisg.net/java/Sunshine.rar
我不知道爲什麼SQLiteDatabase數據庫的insert()方法返回-1。我試圖測試插入到SQLite的工作原理,但它在測試中失敗。
你問題不清楚。你應該描述細節。如果你的問題不清楚,你不能得到任何建議。 – 2014-08-29 10:47:44
你好B男,我修改了我的問題,使其更清晰。抱歉。我感謝您的幫助。 – Krisg 2014-08-29 11:35:21