Espresso

Android单元测试官方support包Espresso使用

不准备做系统化的Api梳理官方文档里面已经很详细说明了Espresso,这里会累计一些坑或者细节。

intended/intending

intended

Asserts that the given matcher matches one and only one intent sent by the application under test. This is an equivalent of verify(mock, times(1)) in Mockito. Verification does not have to occur in the same order as the intents were sent. Intents are recorded from the time that Intents.init is called.

断言只会给matcher匹配一个且只有一个由application发来的intent。类似于Mockito中的verify(mock,times(1))函数,验证过程不需要按照发送intent的相同顺序进行,从Intent.init开始记录。

intending

Enables stubbing intent responses. This method is similar to Mockito.when and is particularly useful when the activity launching the intent expects data to be returned (and especially in the case when the destination activity is external). In this case, the test author can call intending(matcher).thenRespond(myResponse) and validate that the launching activity handles the result correctly. Note: the destination activity will not be launched.

打开stubbing Intent响应,类似于Mockito。当拉起Activity,并预计有Intent返回时(特别是当目标Acticity是外部Acticity时),特别有用。在这种情况下,测试者可以调用intending(matcher).thenRespond(myResponse)并验证拉起Activity是否正确处理结果。Note:目标Activity将不会启动。

作者

8MilesRD

发布于

2019-08-07

更新于

2020-01-16

许可协议

评论