【发布时间】: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