ile çalışmak için Robolectric'i alıyorum Volley, Robolectric ile çalışmaya çalışıyorum. HTTP isteğimin çağrıldığını ve parseNetworkResponse'nin çağrıldığını görebiliyorum (JsonRequest'in özel bir alt sınıfını gönderiyorum), ancak Dinleyici'üm aranmıyor. Herhangi bir tavsiye? İşte bir kod örneği geçerli:Robol
@Test
public void testTypeAheadClient() throws Exception {
Robolectric.getFakeHttpLayer().interceptHttpRequests(false);
//mRemoteRequestQueue and mCustomRequest are set up previously
mRemoteRequestQueue.add(mCustomRequest);
}
private static class CustomRequest extends JsonRequest<MyObject> {
public CustomRequest(String url,
Response.Listener<MyObject> listener,
Response.ErrorListener errorListener) {
super(Request.Method.GET, url, null, listener, errorListener);
}
@Override
protected Response<MyObject> parseNetworkResponse(NetworkResponse response) {
System.out.println("in parseNetworkResponse");
try {
MyObject myObject = new MyObject(new JSONArray(new String(response.data, "UTF-8")));
return Response.success(myObject, HttpHeaderParser.parseCacheHeaders(response));
} catch (Exception e) {
e.printStackTrace();
return Response.error(new ParseError(e));
}
}
}
Geri arama özelliğini kullandığından, bunun bir uyumsuz kütüphanesi olduğunu varsayalım. Android Async Http lib ile Robolectric kullanmak için kendi thread havuzunuzu ayarlamanız gerekir. Belki bu durumda aynı çözüm benimsenebilir. https://groups.google.com/forum/#!msg/robolectric/Z3Yg04gL4hg/iwYlnvHAkO4J – Axxiss
Eğer bunu işe aldıysanız, tüm test kodunuzu gönderebilir misiniz? –