-
Notifications
You must be signed in to change notification settings - Fork 1.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
View height and width are always zero #819
Comments
Anyone have input on this? Seems like a major oversight to me.... but I guess this goes in with the same category as some of my other recent issues dealing with resource loading, and config stuff relating to screen size etc. |
Robolectric isn't trying to emulate Android - just fake enough of it so you can write reasonable unit tests. It doesn't surprise me that views don't have a width or height, since we're not doing anything that would cause a layout pass to happen. What are you trying to test that requires your views to have been measured? |
Hi @erd, I'm testing code for drag and drop, and the drag code implements bounding within the parent |
One workaround here is that you can manually call View.measure(int, int) and View.layout(int, int, int, int) on your content in your test. |
Another option is to use Mockito to mock out the views and have the mocks return the values you would expect. Otherwise you are getting into more integration testing instead of unit testing. |
Thank you for the suggestion, but I don't think we're going to implement this. |
@erd Do you have a good way to accomplish this? Would you recommend the mockito suggestion or the .measure and .layout approach? |
Could we make Robolectric call into doTraversals() as part of the activity
|
I would go with the measure and layout approach if you really need to have your components sized / positioned correctly.
It would make tests slower. Is it worth the trade-off? |
Failing test:
The text was updated successfully, but these errors were encountered: