小编Hem*_*R_D的帖子

robolectric 不支持在 sqlite 中批量插入

我用下面的代码进行了junit测试

@RunWith(RobolectricTestRunner.class)

 public class AccountDAOTest {

}
Run Code Online (Sandbox Code Playgroud)

在我的DadatabaseHelper下面的查询中执行

 public static final String INIT_DATA = "insert into STATE(STATEID, STATENAME, STATECODE) VALUES\n" +
                "(1, 'Jammu and Kashmir', 'JK'),\n" +
                "(2, 'Himachal Pradesh', 'HP')"
  sqlitedatabase.execSQL(INIT_DATA);
Run Code Online (Sandbox Code Playgroud)

上面的代码在模拟器/Android手机上运行。但是当我运行 junit 作为测试时,它失败并抛出以下错误。

android.database.sqlite.SQLiteException: Cannot prepare statement, base error code: 1

at org.robolectric.shadows.ShadowSQLiteConnection.rethrow(ShadowSQLiteConnection.java:56)
at org.robolectric.shadows.ShadowSQLiteConnection.access$500(ShadowSQLiteConnection.java:33)
at org.robolectric.shadows.ShadowSQLiteConnection$Connections.execute(ShadowSQLiteConnection.java:466)
at org.robolectric.shadows.ShadowSQLiteConnection$Connections.prepareStatement(ShadowSQLiteConnection.java:376)
at org.robolectric.shadows.ShadowSQLiteConnection.nativePrepareStatement(ShadowSQLiteConnection.java:67)
at android.database.sqlite.SQLiteConnection.nativePrepareStatement(SQLiteConnection.java)
at android.database.sqlite.SQLiteConnection.acquirePreparedStatement(SQLiteConnection.java:882)
at android.database.sqlite.SQLiteConnection.prepare(SQLiteConnection.java:493)
at android.database.sqlite.SQLiteSession.prepare(SQLiteSession.java:588)
at android.database.sqlite.SQLiteProgram.__constructor__(SQLiteProgram.java:58)
at android.database.sqlite.SQLiteProgram.<init>(SQLiteProgram.java)
at android.database.sqlite.SQLiteStatement.<init>(SQLiteStatement.java)
at android.database.sqlite.SQLiteDatabase.executeSql(SQLiteDatabase.java:1663)
at android.database.sqlite.SQLiteDatabase.execSQL(SQLiteDatabase.java:1594)
at com.bizega.bondacc.database.DatabaseHelper.onCreate(DatabaseHelper.java:145)
at android.database.sqlite.SQLiteOpenHelper.getDatabaseLocked(SQLiteOpenHelper.java:252)
at android.database.sqlite.SQLiteOpenHelper.getWritableDatabase(SQLiteOpenHelper.java:164)
at …
Run Code Online (Sandbox Code Playgroud)

mysql sqlite junit android robolectric

5
推荐指数
0
解决办法
231
查看次数

标签 统计

android ×1

junit ×1

mysql ×1

robolectric ×1

sqlite ×1