使用Robolectric测试HTTPS连接

时间:2015-09-03 09:24:18

标签: android https robolectric

我的项目使用HTTPS:

URL url = new URL("https://blah.com");
HttpsURLConnection urlConnection = (HttpsURLConnection)url.openConnection();
...

是否可以使用Robolectric进行测试?据我所知,FakeHttpLayer似乎无法使用HTTPS:

FakeHttpLayer fakeHttpLayer = new FakeHttpLayer();
fakeHttpLayer.setDefaultHttpResponse(200, "All ok");

对我的应用程序没有影响,该应用程序点击java.net.SocketException: Network is unreachable: connect

(当然,我需要整理证书,以便我的应用程序信任影子。)

1 个答案:

答案 0 :(得分:0)

如果我理解你的评论正确,那么我的建议将是下一个:

  • 创建一个班级use Illuminate\Database\Eloquent\Model; class Transation extends Model { protected $table = 'Trans' . $this->userId; } (按照您的想法正确命名)
  • 将其注入您想要联网的地方
  • 在测试中嘲笑并检查您是否正确调用