使用数据库帮助程序测试服务时出现NoClassDefFoundError ShadowSQLiteConnection错误

时间:2014-09-04 19:57:25

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

我正在尝试使用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:无法解压缩和加载SQLite 库进入C:\ Users \ someone \ AppData \ Local \ Temp \ robolectric-libs \ sqlite4java.d LL

1 个答案:

答案 0 :(得分:-1)

您使用的是旧版本吗?这似乎是个问题。