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

相关内容

热门资讯

透视存在!hhpoker万能辅... 透视存在!hhpoker万能辅助器,拱趴大菠萝有挂吗,技巧教程(素来存在有挂)hhpoker万能辅助...
透视最新!aapoker辅助器... WePoke高级策略深度解析‌;透视最新!aapoker辅助器怎么用,wepoker辅助器是真的吗,...
透视科技!红龙poker脚本,... 透视科技!红龙poker脚本,wepoker正确养号方法,细节方法(本然有挂);值得一提的是,红龙p...
透视讲解!hhpoker辅助软... 透视讲解!hhpoker辅助软件下载,wpk辅助器,扑克教程(原来有挂)是由北京得hhpoker辅助...
透视真的!wepoker辅助器... 透视真的!wepoker辅助器是真的的吗,aapoker辅助软件合法吗,总结教程(切实真的有挂);最...
透视好友!wepoker辅助透... 透视好友!wepoker辅助透视软件,拱趴大菠萝有挂吗,技巧教程(切实真的是有挂);(需添加指定Q群...
透视辅助!wpk辅助工具下载,... 透视辅助!wpk辅助工具下载,wepoker怎么看牌型,解密教程(固有真的是有挂)是一款可以让一直输...
透视计算!wepoker辅助器... 透视计算!wepoker辅助器安装包,哈糖大菠萝怎么挂,微扑克教程(原来有挂)是一款可以让一直输的玩...
透视模拟器!智星菠萝可以辅助吗... 透视模拟器!智星菠萝可以辅助吗,德州辅助工具到底怎么样,2025新版(好像真的有挂);亲真的是有正版...
透视代打!红龙poker脚本,... 《红龙poker脚本软件透明挂》是一款多人竞技的红龙poker脚本辅助透视游戏,你将微扑克对手来到同...