出现通知的 Espresso 测试
Espresso test for Notification to showing up
我想测试当我收到推送时,通知是否会出现。也可以检查其属性(如标题、设置意图等。)
我该怎么做?
@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?
}
Espresso UI 测试框架并没有看到比实际视图更多的内容。我严重怀疑您是否可以使用 Espresso 检查任何通知。
为此使用另一个 Google 测试框架 uiautomator
,描述为:
UI Automator is a UI testing framework suitable for cross-app functional UI testing across system and installed apps.
在这里您可以找到如何将它与 Espresso 一起使用:http://qathread.blogspot.com/2015/05/espresso-uiautomator-perfect-tandem.html
更多信息:
- 文档(一):
https://google.github.io/android-testing-support-library/docs/uiautomator/index.html
- 文档(二):
http://developer.android.com/intl/es/training/testing/ui-testing/uiautomator-testing.html
另请访问:Android Testing: UIAutomator vs 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?
}
Espresso UI 测试框架并没有看到比实际视图更多的内容。我严重怀疑您是否可以使用 Espresso 检查任何通知。
为此使用另一个 Google 测试框架 uiautomator
,描述为:
UI Automator is a UI testing framework suitable for cross-app functional UI testing across system and installed apps.
在这里您可以找到如何将它与 Espresso 一起使用:http://qathread.blogspot.com/2015/05/espresso-uiautomator-perfect-tandem.html
更多信息:- 文档(一): https://google.github.io/android-testing-support-library/docs/uiautomator/index.html
- 文档(二): http://developer.android.com/intl/es/training/testing/ui-testing/uiautomator-testing.html
另请访问:Android Testing: UIAutomator vs Espresso