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);
    }
}

相关内容

热门资讯

科技新动态!智星德州扑克辅助挂... 科技新动态!智星德州扑克辅助挂多功能透视工具,一贯存在有挂(有挂详情)1)智星德州扑克辅助插件:进一...
来一盘!德扑之星辅助挂多功能透... 来一盘!德扑之星辅助挂多功能透视工具,原来真的有挂(竟然有挂)亲,关键说明,德扑之星透视脚本安卓赛季...
今日科普!德普之星辅助挂多功能... 今日科普!德普之星辅助挂多功能透视工具,都是有挂(有挂详情)1、今日科普!德普之星辅助挂多功能透视工...
一分钟了解!德扑之星辅助挂多功... 一分钟了解!德扑之星辅助挂多功能透视工具,总是存在有挂(讲解有挂)1、德扑之星公共底牌简单,德扑之星...
推荐几款新版!wepoker辅... 推荐几款新版!wepoker辅助挂多功能透视工具,竟然是有挂(新版有挂)1、wepoker脚本辅助下...
今日科普!红龙poker辅助挂... 今日科普!红龙poker辅助挂多功能透视工具,一贯真的是有挂(有挂解密)1、让任何用户在无需红龙po...
盘点一款!aapoker辅助挂... 盘点一款!aapoker辅助挂多功能透视工具,一直是真的有挂(有挂透明挂)1、每一步都需要思考,不同...
专业讨论!WPK辅助挂多功能透... 专业讨论!WPK辅助挂多功能透视工具,总是真的是有挂(果真有挂)WPK辅助器是一种具有地方特色的麻将...
实测教程!德扑圈辅助挂多功能透... 实测教程!德扑圈辅助挂多功能透视工具,其实真的有挂(新版有挂)1、打开软件启动之后找到中间准星的标志...
分享一款!智星菠萝德州辅助挂多... 分享一款!智星菠萝德州辅助挂多功能透视工具,果然是真的有挂(存在有挂)亲,关键说明,智星菠萝德州透视...