不能捕捉robolectric HTTP请求 [英] Can't capture HTTP request with robolectric

查看:109
本文介绍了不能捕捉robolectric HTTP请求的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想捕捉Robolectric http请求 该方法标记化方法发送一个请求到服务器,我只是想测试后发送: 如果我尝试

I am trying to capture an http request with Robolectric The method tokenize method sends a request to a server and I just want to test that the post is sent: If I try

//Cardtest.java

Robolectric.setDefaultHttpResponse(200, "dummy");
card.tokenize(paymentHandler);
Robolectric.getSentHttpRequest(0);

在我有一个空数组错误

The I have an empty array error

但我知道,请求被发送,因为如果我删除的第一行,我有以下错误:

But I know that the request is sent because if I remove the first line I have the following error:

Unexpected HTTP call POST

如果我把日志语句,似乎我的成功不调用这个块的http请求。

If I put log statement it appears that my success block is never called for an http request.

我如何能确保我的HTTP请求的成功回调被调用。

How can I make sure that my HTTP request success call back get called.

(我已经尝试Robolectric.runUiThreadTasksIncludingDelayedTasks();)

(I already try Robolectric.runUiThreadTasksIncludingDelayedTasks();)

感谢

推荐答案

正如我们在评论中讨论。问题是,因为 Robolectric 配置为不拦截HTTP请求:

As we discussed in comments. The issue was because Robolectric was configured to do not intercept http requests:

Robolectric.getFakeHttpLayer().interceptHttpRequests(false)

这篇关于不能捕捉robolectric HTTP请求的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆