有没有可能在Android中使用Robospice模拟响应,因为我需要创建演示应用程序,它将在应用程序的json文件中包含所有响应?我正在尝试使用https://github.com/andrzejchm/RESTMock,但出现了一些问题,我得到的信息是:RESTMock successfully started! url: http://localhost:34163/,没有其他信息。还有别的主意吗?
发布于 2017-07-03 16:59:13
在您的Application类中,您可以使用以下命令启动RESTMock:
@Override
public void onCreate() {
super.onCreate();
RESTMockServerStarter.startSync(new AndroidAssetsFileParser(getContext()),new AndroidLogger());
RESTMockServer.whenRequested(pathContains("response"))
.thenReturnFile(200, "response.json");
}这确实设置了您的RESTMock服务器,但到目前为止还没有执行任何http请求。现在,您需要将RESTMock的服务器url提供给获取数据的方法。例如,如果您正在使用Retrofit:
Retrofit retrofit = new Retrofit.Builder()
.baseUrl(RESTMockServer.getUrl())
.build();从现在开始,使用retrofit发出的每个请求都应该直接与RESTMock服务器通信,并正确地获取您指定为模拟的响应。
https://stackoverflow.com/questions/44325014
复制相似问题