Android 在改造中模拟客户端-回调对象为null
我遵循这里提到的关于测试中模拟改造的建议: 看起来我很接近这个概念,除了返回对象为null。以下是我如何构建我的 模拟供应商响应:Android 在改造中模拟客户端-回调对象为null,android,mocking,httpresponse,retrofit,Android,Mocking,Httpresponse,Retrofit,我遵循这里提到的关于测试中模拟改造的建议: 看起来我很接近这个概念,除了返回对象为null。以下是我如何构建我的 模拟供应商响应: public Response getVendorsResponse(String url) { String responseString = ""; if (url.contains("category=one")) { responseString = mFixturesMan.use("one_all"); } el
public Response getVendorsResponse(String url) {
String responseString = "";
if (url.contains("category=one")) {
responseString = mFixturesMan.use("one_all");
} else if (url.contains("category=two")) {
responseString = mFixturesMan.use("two_all");
}
return new Response(
url,
200,
"nothing",
Collections.EMPTY_LIST,
new TypedByteArray("application/json", responseString.getBytes()));
}
我的回电如下:
@Override
public void success(MyResult result, Response response) {
// result is null when mocked.
displayResult(result.getTitle());
}
在调试时,我期望的响应会通过。我看到了我设置的状态和原因
这是否意味着作为响应传递的数据是错误的?或者其他事情可能是错的?我已经从一个我知道有效的真实响应中复制(并稍微修改)了文本,所以可能是坏数据。不过,我似乎找不到错误的根源