AndroidUI测试由于mockwebserver而失败
创始人
2024-08-22 00:00:18
0
  1. 确保mockwebserver运行在一个单独的线程中,这样它不会阻塞UI线程。
@Rule
public final ExecutorServiceRule executorServiceRule = new ExecutorServiceRule();
private MockWebServer server;

@Before
public void setUp() throws Exception {
    server = new MockWebServer();
    server.start();
}

public void testMyUi() throws Exception {
    server.enqueue(new MockResponse().setBody("hello, world!"));
    onView(withId(R.id.my_button)).perform(click());
    RecordedRequest request = server.takeRequest();
    assertThat(request.getPath(), equalTo("/hello"));
}
  1. 如果您发现您的UI测试在MockWebServer启动后仍然失败,那么您可能需要使用idling资源来等待服务器响应。
@Test
public void testMyUi() throws Exception {
    server.enqueue(new MockResponse().setBody("hello, world!"));
    onView(withId(R.id.my_button)).perform(click());
    // Wait until the server has received the request, 
    // fired the callback, and delivered the response.
    IdlingResource idlingResource = OkHttp3IdlingResource.create("OkHttp", client);
    IdlingRegistry.getInstance().register(idlingResource);
    try {
        RecordedRequest request = server.takeRequest();
        assertThat(request.getPath(), equalTo("/hello"));
    } finally {
        IdlingRegistry.getInstance().unregister(idlingResource);
    }
}

相关内容

热门资讯

教程攻略!wepoker底牌透... 教程攻略!wepoker底牌透视(辅助挂)确实有挂(有挂解密)1、这是跨平台的wepoker底牌透视...
实测发现!werplan怎么作... 您好,werplan怎么作弊这款游戏可以开挂的,确实是有挂的,需要了解加去威信【136704302】...
揭秘一下!hhpoker作弊码... 揭秘一下!hhpoker作弊码(辅助挂)总是是真的有挂(有挂实锤);hhpoker作弊码辅助器是一种...
推荐一款!newpoker脚本... 推荐一款!newpoker脚本(辅助挂)都是存在有挂(有挂分享)newpoker脚本脚本下载中分为三...
一分钟揭秘!wepoker养号... 一分钟揭秘!wepoker养号规律(辅助挂)切实是有挂(有挂方法)1、wepoker养号规律辅助器安...
玩家必看分享!德州局怎么透视(... 玩家必看分享!德州局怎么透视(辅助挂)竟然真的是有挂(真的有挂)1、操作简单,无需德州局怎么透视手机...
重要通知!aapoker脚本怎... 重要通知!aapoker脚本怎么用(辅助挂)果然真的有挂(有挂分享)1、aapoker脚本怎么用模拟...
玩家交流!hh poker辅助... 玩家交流!hh poker辅助有用吗(辅助挂)竟然存在有挂(确实有挂)hh poker辅助有用吗透视...
教程攻略!德州透视竞技联盟(辅... 教程攻略!德州透视竞技联盟(辅助挂)其实是有挂(有挂工具)1、打开软件启动之后找到中间准星的标志长按...
分享认知!hhpoker有辅助... 分享认知!hhpoker有辅助吗(辅助挂)真是是有挂(存在有挂)1、超多福利:超高返利,海量正版游戏...