0

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.

mars8
  • 770
  • 1
  • 11
  • 25

1 Answers1

1

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

Marcel
  • 2,094
  • 3
  • 23
  • 37
  • thanks, I see that there is an `AppWidgetHostView.exportSnapshot` function in the appwidget-host library. Am I correct in thinking that this could be used in my app production to draw on a canvas, convert to bitmap and then show in remoteView? i.e. used as an alternate approach to answer [this](https://stackoverflow.com/q/74248679/15597975) question? – mars8 Dec 02 '22 at 09:08
  • 1
    Those are two different things. If you want to render remote views inside your app you can use the approach describe above. If you want to render a custom UI inside glance/widget it's a different thing. Then you can use the export approach indeed – Marcel Jan 02 '23 at 09:04
  • The source code you provided has a different object for [GlanceAppWidget](https://cs.android.com/androidx/platform/frameworks/support/+/androidx-main:glance/glance-appwidget/src/androidMain/kotlin/androidx/glance/appwidget/GlanceAppWidget.kt;l=59?q=provideGlance&ss=androidx%2Fplatform%2Fframeworks%2Fsupport) than the one provided in the latest Glance release 1.0.0-alpha05. How can i reconcile the source code to a live project in Android Studio? i.e. I don't know how to apply this test source code to my current project. – mars8 Mar 05 '23 at 20:28
  • created question [here](https://stackoverflow.com/questions/75645615/how-to-apply-android-code-search-examples-that-use-different-source-sets-in-andr) – mars8 Mar 05 '23 at 22:12