Robolectric.application被初始化,所有其他测试运行顺利.
尝试得到嘲笑的http响应时,我收到此错误.
这是我的考验
@RunWith(MyRobolectricTestRunner.class)public class APITests { @Inject protected API API; @Before public voID setUp() { ObjectGraph.create(new AndroIDModule(Robolectric.application),new TestApplicationModule()).inject(this); } @Test public voID shouldGetErrorList() throws Exception { Project project = new Project("test","test",DateTime.Now()); addPendingProjectsErrorsResponse("response.Json"); //adding response to FakehttpLayer API.getProjectErrors(project,new Listener<ProjectErrors>() { @OverrIDe public voID onResponse(ProjectErrors response) { assertNotNull(response); } },new ErrorListener() { @OverrIDe public voID onErrorResponse(VolleyError error) { throw new RuntimeException(error); } } ); }}
这是我得到的错误:
Exception in thread "Thread-3" java.lang.NullPointerException at org.robolectric.shadows.ShadowLooper.getMainLooper(ShadowLooper.java:59) at androID.os.Looper.getMainLooper(Looper.java) at org.robolectric.Robolectric.getUiThreadScheduler(Robolectric.java:1301) at org.robolectric.shadows.ShadowSystemClock.Now(ShadowSystemClock.java:15) at org.robolectric.shadows.ShadowSystemClock.uptimeMillis(ShadowSystemClock.java:25) at org.robolectric.shadows.ShadowSystemClock.elapsedRealtime(ShadowSystemClock.java:30) at androID.os.SystemClock.elapsedRealtime(SystemClock.java) at com.androID.volley.VolleyLog$MarkerLog.add(VolleyLog.java:114) at com.androID.volley.Request.addMarker(Request.java:174) at com.androID.volley.Cachedispatcher.run(Cachedispatcher.java:92)解决方法 我有同样的错误,并避免使用我自己(和丑)的SystemClock阴影.
影子类:
@Implements(value = SystemClock.class,callThroughByDefault = true)public static class MyShadowSystemClock { public static long elapsedRealtime() { return 0; }}
测试代码:
@Test@Config(shadows = { MyShadowSystemClock.class,... })public voID mytest() {}总结
以上是内存溢出为你收集整理的android – NPE当与Volley和Dagger获得Robolectric ShadowApplication时全部内容,希望文章能够帮你解决android – NPE当与Volley和Dagger获得Robolectric ShadowApplication时所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)