相关疑难解决方法(0)

Robolectric:运行多个测试失败

我正在尝试使用SQLite(OpenHelper)作为数据库,使用Robolectric 3.0 + Gradle运行多个测试.运行每个单独的测试工作正常,但启动整个测试套件总是在第二次测试中导致RuntimeException.

这是我的测试假人,不起作用.

@RunWith(RobolectricGradleTestRunner.class)
@Config(constants = BuildConfig.class, sdk = 21)
public class Dummy {


    @Before
    public void setUp() throws Exception {
         // setup activity ...
    }

    @Test
    public void testA() throws Exception {
        Assert.assertTrue(true);
    }

    @Test
    public void testB() {
        Assert.assertTrue(true);
    }
}
Run Code Online (Sandbox Code Playgroud)

例外

java.lang.RuntimeException: java.lang.IllegalStateException: Illegal connection pointer 1. Current pointers for thread Thread[pool-4-thread-1,5,main] []
    at org.robolectric.shadows.ShadowSQLiteConnection$Connections.execute(ShadowSQLiteConnection.java:470)
    at org.robolectric.shadows.ShadowSQLiteConnection.nativeResetStatementAndClearBindings(ShadowSQLiteConnection.java:286)
    at android.database.sqlite.SQLiteConnection.nativeResetStatementAndClearBindings(SQLiteConnection.java)
    at android.database.sqlite.SQLiteConnection.releasePreparedStatement(SQLiteConnection.java:915)
    at android.database.sqlite.SQLiteConnection.prepare(SQLiteConnection.java:519)
    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) …
Run Code Online (Sandbox Code Playgroud)

android robolectric sqliteopenhelper

14
推荐指数
1
解决办法
3099
查看次数

标签 统计

android ×1

robolectric ×1

sqliteopenhelper ×1