androidandroid-testingandroid-uiautomatorremoteviewglance-appwidget

Where can I find examples of testing interactions with android homescreen widgets?


I see very little information on how to test RemoteViews. For example, I have used UiAutomator to place an app widget on the homescreen and now i want to test if it updates correctly when I click on it.

Does anybody know good resources and examples for testing of RemoteView interaction?

Note, I am familiar with the resources on Android Developers site explaining RemoteViews and UiAutomator. I am after something more specific on checking RemoteViews are working as expected.


Solution

  • The best way is to host the RemotViews/Widget inside your activity and use the normal UI testing tools.

    For example, you could use the AppWidgetHost from https://github.com/google/glance-experimental-tools/tree/main/appwidget-host. It works for RemoteViews as well as Glance.

    We use similar mechanism to test Glance-appwidgets. You can check the source code here: https://cs.android.com/androidx/platform/frameworks/support/+/androidx-main:glance/glance-appwidget/src/androidAndroidTest/kotlin/androidx/glance/appwidget/CheckBoxTest.kt