在sqlite中的批量插入不受robolectric的支持

时间:2017-11-04 10:10:48

标签: android mysql sqlite junit robolectric

我使用以下代码进行junit测试

@RunWith(RobolectricTestRunner.class)

 public class AccountDAOTest {

}

在我的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);

以上代码在模拟器/ 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 AccountDAOTest.setUp(AccountDAOTest.java:32)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:44)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:41)
at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:27)
at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:31)

对此的任何帮助都将受到高度赞赏。

提前致谢。

0 个答案:

没有答案