jeudi 9 avril 2015

Set screen width programmatically in test?

I have a custom View that inflates a layout that differs based on screen width. When enough horizontal space is available, the layout in layout-w400dp/view_widget.xml is used. Otherwise layout/view_widget.xml is used.


Both versions of the layout are very similar but one of them contains a view that doesn't exist in the other. I want to write a test that verifies that WidgetView is initialized correctly for both versions of the layout.


I believe that LayoutInflater#inflate() will pick which version of the layout it uses based on the device that's running the test. Is there any way to force inflate() to pick a certain version? It seems like setting the screen's width programmatically would cause inflate() to pick one version over the other, but there doesn't seem to be a way to do that. Is there? Or is there a better way to test something like this?


I can write this test as either an Android Junit or using Robolectric.


Aucun commentaire:

Enregistrer un commentaire