1、错误信息:
Caused by: java.lang.ClassNotFoundException: javax.microedition.khronos.opengles.GL :
解决办法
添加testCompile 'org.khronos:opengl-api:gl1.1-android-2.1_r1'
来自:https://github.com/robolectric/robolectric/issues/1932
2、错误信息(使用数据库为greenDao3.2.0
):
java.lang.RuntimeException: java.util.concurrent.ExecutionException: java.lang.IllegalStateException: Illegal connection pointer 141. Current pointers for thread Thread[pool-8-thread-1,5,main] []
解决办法:
在tearDown()
中将daoSession和XXXDao设为null
来自:
https://github.com/robolectric/robolectric/issues/2010
https://github.com/robolectric/robolectric/issues/1890
Android单元测试框架Robolectric3.0介绍(二)中数据库部分
@After
public void tearDown() throws Exception {
TestUtils.resetSingleton(DbManager.class, "instance");
TestUtils.resetSingleton(ContactDaoHelper.class, "contactDaoHelper");
}
public static void resetSingleton(Class clazz, String fieldName) {
Field instance;
try {
instance = clazz.getDeclaredField(fieldName);
instance.setAccessible(true);
instance.set(null, null);
} catch (Exception e) {
throw new RuntimeException();
}
}
网友评论