是否有可能做robolectric真正的http请求 [英] Is it possible to do real http requests with robolectric

查看:461
本文介绍了是否有可能做robolectric真正的http请求的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这个问题我有robolectric是,它并没有取得真正的Htt prequests。

The issue I have with robolectric is that it doesn't make real HttpRequests.

我可以取代HttpClient的执行robolectric使用一个真正的人真正进行调用,以我的本地测试服务器?

Could I replace the HttpClient implementation of robolectric using a real one actually making the calls to my local test server?

推荐答案

扬伯克尔提交拉入请求以Robolectric被合并到主在3月8日。现在你可以叫 Robolectric.getFakeHttpLayer()interceptHtt prequests(假); 在您的测试绕过Robolectric嘲笑的HTTP层的开头。

Jan Berkel submitted a pull request to Robolectric that was merged into master on March 8th. You can now call Robolectric.getFakeHttpLayer().interceptHttpRequests(false); in the beginning of your test to bypass the mocked http layer in Robolectric.

您可以直接从 Sonatype的下载JAR在Eclipse Android项目包括。如果您正在使用Maven和1.1尚未公布(请在Sonatype的URL以上),那么你将需要添加Sonatype的快照回购和使用robolectric 1.1快照。您可以通过添加以下到您的pom.xml做到这一点

You can download the jar directly from Sonatype to include in your Eclipse Android project. If you are using Maven and 1.1 has not yet been released (check at the Sonatype url above) then you will need to add the sonatype snapshot repo and use robolectric 1.1-SNAPSHOT. You can do this by adding the following to your pom.xml

<repositories>
    <repository>
        <id>sonatype-snapshots</id>
        <name>Sonatype Snapshots</name>
        <layout>default</layout>
        <url>https://oss.sonatype.org/content/repositories/snapshots</url>
        <snapshots>
            <enabled>true</enabled>
        </snapshots>
    </repository>
</repositories>
...
<dependencies>
   <dependency>
        <groupId>com.pivotallabs</groupId>
        <artifactId>robolectric</artifactId>
        <version>1.1-SNAPSHOT</version>
        <scope>test</scope>
    </dependency>
    ...
</dependencies>

我用这对集成测试运行对一个真正的服务器,它工作得很好。

I am using this for integration test that run against a real server and it works well.

这篇关于是否有可能做robolectric真正的http请求的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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