1

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.

1 Answer 1

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

Sign up to request clarification or add additional context in comments.

4 Comments

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 question?
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
The source code you provided has a different object for GlanceAppWidget 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.
created question here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.