【问题标题】:NoClassDefFoundError ShadowSQLiteConnection Error When Testing Service With Database Helper使用数据库助手测试服务时出现 NoClassDefFoundError ShadowSQLiteConnection 错误
【发布时间】:2014-09-04 19:57:25
【问题描述】:

我正在尝试使用 Robolectric 测试服务。碰巧服务创建了一个数据库连接检查某些东西然后关闭。问题是我收到一个 Robo 错误,它找不到类。

Could not initialize class org.robolectric.shadows.ShadowSQLiteConnection

java.lang.NoClassDefFoundError: Could not initialize class org.robolectric.shadows.ShadowSQLiteConnection
at java.lang.Class.newInstance(Class.java:374)
at org.robolectric.bytecode.ShadowWrangler.createShadowFor(ShadowWrangler.java:354)
at org.robolectric.bytecode.ShadowWrangler.initializing(ShadowWrangler.java:81)
at org.robolectric.bytecode.RobolectricInternals.initializing(RobolectricInternals.java:72)
at android.database.sqlite.SQLiteConnection.$$robo$init(SQLiteConnection.java)
at android.database.sqlite.SQLiteConnection.<init>(SQLiteConnection.java:162)
at android.database.sqlite.SQLiteConnection.open(SQLiteConnection.java:190)
at android.database.sqlite.SQLiteConnectionPool.openConnectionLocked(SQLiteConnectionPool.java:463)
at android.database.sqlite.SQLiteConnectionPool.open(SQLiteConnectionPool.java:185) ...

我调用它的代码是:

@Config(manifest = "../App/AndroidManifest.xml",shadows = { MyShadowSystemClock.class})
@RunWith(RobolectricTestRunner.class)
public class DataServiceTest {

    MyActivity activity;
    Context context;

    @Before
    public void setUp() throws Exception {
        ShadowLog.stream = System.out;
    }

    @Test
    public void testServiceActionReference() throws InterruptedException {
        Intent startIntent = new Intent(Robolectric.application, DataService.class);
        startIntent.setAction("GET_DATA");
        DataService service = new DataService();
        service.onCreate();
        service.onStartCommand(startIntent, 0, 42);
        service.onHandleIntent(startIntent);
           assertEquals(DataService.class.getCanonicalName(),startIntent.getComponent().getClassName());
        service.stopService(startIntent);
        service.onDestroy();
    }
}

为了防止这些错误,我遗漏了什么?

在运行 ant 时也可以在 sys out 上看到这个:

原因:java.lang.RuntimeException: Cannot extractAndLoad SQLite 库到 C:\Users\someone\AppData\Local\Temp\robolectric-libs\sqlite4java.d 会

【问题讨论】:

    标签: android sqlite unit-testing android-service robolectric


    【解决方案1】:

    您使用的是非常旧的版本吗?这似乎是问题所在。

    【讨论】:

    • 我不是,但也许机器人是?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-03-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-11-08
    • 2022-11-03
    • 2016-11-10
    相关资源
    最近更新 更多