Android robolectric不支持sqlite中的大容量插入
我用下面的代码进行了junit测试Android robolectric不支持sqlite中的大容量插入,android,mysql,sqlite,junit,robolectric,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
@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)
android.database.sqlite.SQLiteException:无法准备语句,基本错误代码:1
位于org.roblectric.shadows.ShadowSQLiteConnection.rethrow(ShadowSQLiteConnection.java:56)
位于org.roblectric.shadows.ShadowSQLiteConnection.access$500(ShadowSQLiteConnection.java:33)
位于org.roblectric.shadows.ShadowSQLiteConnection$Connections.execute(ShadowSQLiteConnection.java:466)
位于org.roblectric.shadows.ShadowSQLiteConnection$Connections.prepareStatement(ShadowSQLiteConnection.java:376)
位于org.roblectric.shadows.ShadowSQLiteConnection.nativePrepareStatement(ShadowSQLiteConnection.java:67)
在android.database.sqlite.SQLiteConnection.nativePrepareStatement(SQLiteConnection.java)中
位于android.database.sqlite.SQLiteConnection.acquirePreparedStatement(SQLiteConnection.java:882)
位于android.database.sqlite.SQLiteConnection.prepare(SQLiteConnection.java:493)
位于android.database.sqlite.SQLiteSession.prepare(SQLiteSession.java:588)
在android.database.sqlite.SQLiteProgram.\uuuuu构造函数\uuuuu(SQLiteProgram.java:58)
位于android.database.sqlite.SQLiteProgram.(SQLiteProgram.java)
位于android.database.sqlite.SQLiteStatement.(SQLiteStatement.java)
位于android.database.sqlite.SQLiteDatabase.executeSql(SQLiteDatabase.java:1663)
位于android.database.sqlite.SQLiteDatabase.execSQL(SQLiteDatabase.java:1594)
位于com.bizega.bondacc.database.DatabaseHelper.onCreate(DatabaseHelper.java:145)
位于android.database.sqlite.SQLiteOpenHelper.getDatabaseLocked(SQLiteOpenHelper.java:252)
位于android.database.sqlite.SQLiteOpenHelper.getWritableDatabase(SQLiteOpenHelper.java:164)
在AccountDAOTest.setUp(AccountDAOTest.java:32)
位于org.junit.runners.model.FrameworkMethod$1.runReflectVeCall(FrameworkMethod.java:44)
位于org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
位于org.junit.runners.model.FrameworkMethod.invokeeexplosive(FrameworkMethod.java:41)
位于org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:27)
位于org.junit.internal.runners.statements.runafter.evaluate(runafter.java:31)
在此方面的任何帮助都将不胜感激
提前感谢。您有没有找到解决方案?