use*_*345 6 android android-testing android-uiautomator
我的Android应用程序有一个服务,根据应用程序的运行次数等参数向用户发送通知.通知在不同情况下的不同时间发送.我想测试在所有不同情况下是否在正确的时间发送通知.android是否提供了这种测试方式?
小智 10
使用UIAutomator测试通知:
只需浏览以下代码即可.它将帮助您测试通知.
UiDevice device = UiDevice.getInstance(InstrumentationRegistry.getInstrumentation());
device.openNotification();
device.wait(Until.hasObject(By.text(NOTIFICATION_TITLE)), TIMEOUT);
UiObject2 title = device.findObject(By.text(NOTIFICATION_TITLE));
UiObject2 text = device.findObject(By.text(NOTIFICATION_TEXT));
assertEquals(NOTIFICATION_TITLE, title.getText());
assertEquals(NOTIFICATION_TEXT, text.getText());
title.click();
device.wait(Until.hasObject(By.text(ESPRESSO.getName())), TIMEOUT);
Run Code Online (Sandbox Code Playgroud)
不要忘记添加UIAutomator依赖项build.gradle.
// UIAutomator dependency
androidTestCompile 'com.android.support.test.uiautomator:uiautomator-v18:2.1.1'
Run Code Online (Sandbox Code Playgroud)
请阅读这篇文章
http://qathread.blogspot.com/2015/05/espresso-uiautomator-perfect-tandem.html
这是这个主题的一个很好的解释:
Espressofor Android 是完美且快速的测试自动化框架,但它有一个重要的限制 - 您只能在测试上下文下的应用程序内进行操作。这意味着,不可能对应用程序功能进行自动化测试,例如:
- 应用程序推送通知
- 联系人同步
- 从另一个应用程序导航到正在测试的应用程序,
由于您必须处理移动设备上的其他应用程序 -
NotificationBar或Contacts应用People程序等。事实上,直到
UIAutomator 2.0. 正如 Android 开发者博客文章中所述 - “...最重要的是,UI Automator现在基于 Android Instrumentation...”。因此,我们可以运行UIAutomator测试以及Espresso使用Instrumentation test runner.除此之外,我们可以将 UIAutomator 测试与
Espresso测试结合起来,这为我们提供了对被测手机和应用程序的真正力量和控制。
| 归档时间: |
|
| 查看次数: |
8236 次 |
| 最近记录: |