Skip to content

TextViews on Robolectric always have width and height 0 #4153

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

Closed
brettchabot opened this issue Nov 15, 2018 · 4 comments
Closed

TextViews on Robolectric always have width and height 0 #4153

brettchabot opened this issue Nov 15, 2018 · 4 comments
Assignees
Labels
espresso support Espresso compatibility with robolectric
Milestone

Comments

@brettchabot
Copy link
Contributor

Description

TextViews on Robolectric always seem to have a width and height of 0. This makes Espresso think they are always not displayed

Steps to Reproduce

TextView textView = ....
assertThat(textView.getGlobalVisibleRectangle(new Rect())).isTrue(); // Fails

Robolectric & Android Version

Robolectric 4.0.2, Android 28

Link to a public git repo demonstrating the problem:

https://github.com/googlesamples/android-testing CustomMatcherSample

@brettchabot brettchabot added the espresso support Espresso compatibility with robolectric label Nov 15, 2018
@brettchabot brettchabot added this to the 4.1 milestone Nov 15, 2018
@stankinzl
Copy link

The same problem.

@mvescovo
Copy link

mvescovo commented Mar 8, 2019

Me too.

copybara-robolectric pushed a commit that referenced this issue Mar 13, 2019
Fixes #4236, #4153

PiperOrigin-RevId: 224888389
@hakemcpu
Copy link

hakemcpu commented Mar 16, 2019

I was having the same problem as well, but now issue fixed when used 4.2.1 and setting the width and hight manually in the xml. If they are set to wrap content it doesn't work.

I was able to get it to work by setting minHeight for the TextViews (this should mitigate the issue until we get a fix).
Thanks

copybara-robolectric pushed a commit that referenced this issue Mar 30, 2019
Fixes #4236, #4153

This change makes UI layout and text measurement in Robolectric more realistic,
by shadowing additional native text measurement calls and setting a valid, non-zero window frame size during UI layout.

Some tests may need adjustment after this change in the following ways:
 - switched to paused looper when doing layouts, especially when RecyclerView is used. See #3369. Its recommended to use the upcoming @LooperMode(PAUSED)
 - adjust screen size or other dimensions of tests to account for the fact that TextViews are no longer always 0-sized

Because of this potential effect on tests, the new layout logic is turned off by default for now, but can be enabled via the @LayoutMode(REALISTIC) annotation.

PiperOrigin-RevId: 241141684
copybara-robolectric pushed a commit that referenced this issue Mar 30, 2019
…tric

Fixes #4236, #4153

This change makes UI layout and text measurement in Robolectric more realistic,
by shadowing additional native text measurement calls and setting a valid, non-zero window frame size during UI layout.

Some tests may need adjustment after this change in the following ways:
- switched to paused looper when doing layouts, especially when RecyclerView is used. See https://github.com/robolectric/robolectric/...

PiperOrigin-RevId: 241153371
@brettchabot
Copy link
Contributor Author

Fixed if you use @TextLayoutMode(REALISTIC)

I'll track switching TextLayoutMode to default to REALISTIC in a separate issue

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
espresso support Espresso compatibility with robolectric
Projects
None yet
Development

No branches or pull requests

5 participants