美文网首页
Robolectric错误解决

Robolectric错误解决

作者: CaiBird | 来源:发表于2017-03-06 18:09 被阅读151次

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();
    }
}

相关文章

网友评论

      本文标题:Robolectric错误解决

      本文链接:https://www.haomeiwen.com/subject/dlpugttx.html