Espresso测试通知显示

Dmi*_*din 7 android android-espresso

我想测试一下,当我收到推送时,通知将会出现.也可以检查其属性(如标题,设置意图等).

我怎么能这样做?

 @Before
public void setupTest() {

    mData.putString(PushNotificator.KEY_PUSH_TYPE, PushType.PROJECT_OFFER.toString());
    mData.putString(PushNotificator.KEY_PUSH_OBJECT, pushObjectJsonString);
    mContext = InstrumentationRegistry.getContext();

}

@Test
public void projectOfferCreatedFromBundle() {
    mPushNotificator = new PushNotificator(mContext);
    mPushNotificator.processPush(mData);
    onView(withText("111")).check(matches(withText("111")));  //how to find notification?
}
Run Code Online (Sandbox Code Playgroud)

pio*_*543 13

Espresso UI测试框架看不到超过实际的View.我非常怀疑您可以使用Espresso查看任何通知.

为此目的,使用另一个Googles测试框架uiautomator,其描述如下:

UI Automator是一个UI测试框架,适用于跨系统和已安装应用程序的跨应用程序功能UI测试.

在这里,您将找到如何与Espresso一起使用:http://qathread.blogspot.com/2015/05/espresso-uiautomator-perfect-tandem.html

更多信息:

访问:Android测试:UIAutomator vs Espresso