任何人都取得了成功嘲讽的Htt prequests与Robolectric? [英] Anyone had success mocking HttpRequests with Robolectric?
问题描述
我刚开始用Robolectric。这似乎是工作的罚款嘲笑大多数Android类,但是当我在测试类尝试创建一个DefaultHttpClient()它得到可怕的存根!错误。
I'm just starting with Robolectric. It seems to be working fine to mock most Android classes but when my class under test tries to create a DefaultHttpClient() it gets the dreaded "Stub!" error.
测试的类别在此行失败:
The class under test fails at this line:
HttpClient httpclient = new DefaultHttpClient();
尽管文章在<一个href=\"http://robolectric.blogspot.com/2011/01/how-to-test-http-requests.html?showComment=1297722651278#c3540420071421225744\">http://robolectric.blogspot.com/2011/01/how-to-test-http-requests.html?showComment=1297722651278#c3540420071421225744似乎暗示这应该只是工作。
even though the article at http://robolectric.blogspot.com/2011/01/how-to-test-http-requests.html?showComment=1297722651278#c3540420071421225744 seems to suggest this should just work.
我的测试是这样的:
@Before
public void setUp() throws Exception
{
Robolectric.addPendingHttpResponse(200, "OK");
service = new CheckinService();
}
@Test
public void testIt() throws IOException
{
// Fails at HttpClient httpclient = new DefaultHttpClient()
service.doStuff(Robolectric.application,
REG_ID,
TEST_DOMAIN);
}
任何想法,我做错了吗?
Any idea what I'm doing wrong?
推荐答案
日食内固定它。
我花了一段时间才能找出如何解决这个问题,但在这里它是:
转到您的测试项目preferences>构建路径>为了和放大器;出口>选择robolectric罐子,preSS移动到顶部
Fixed it within eclipse. Took me a while to figure out how to fix that but here it is: Go to your test project preferences > build path > order&export > select robolectric jar and press move to top.
这篇关于任何人都取得了成功嘲讽的Htt prequests与Robolectric?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!