Skip to content
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

TextViews on Robolectric always have width and height 0 #4153

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

Comments

@brettchabot
Copy link
Contributor

commented Nov 15, 2018

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 this to the 4.1 milestone Nov 15, 2018

@mageRabbitStudios

This comment has been minimized.

Copy link

commented Dec 3, 2018

The same problem.

@mvescovo

This comment has been minimized.

Copy link

commented Mar 8, 2019

Me too.

copybara-robolectric added a commit that referenced this issue Mar 13, 2019

Fix zero-sized TextViews in Robolectric
Fixes #4236, #4153

PiperOrigin-RevId: 224888389
@hakemcpu

This comment has been minimized.

Copy link

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 added a commit that referenced this issue Mar 29, 2019

Introduce an opt-in mode that fixes zero-sized TextViews in Robolectric
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: 240880657

copybara-robolectric added a commit that referenced this issue Mar 30, 2019

Introduce an opt-in mode that fixes zero-sized TextViews in Robolectric
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: 240880657

copybara-robolectric added a commit that referenced this issue Mar 30, 2019

Introduce an opt-in mode that fixes zero-sized TextViews in Robolectric
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: 240880657

copybara-robolectric added a commit that referenced this issue Mar 30, 2019

Introduce an opt-in mode that fixes zero-sized TextViews in Robolectric
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 added a commit that referenced this issue Mar 30, 2019

Reintroduce an opt-in mode that fixes zero-sized TextViews in Robolec…
…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: 241150766

copybara-robolectric added a commit that referenced this issue Mar 30, 2019

Reintroduce an opt-in mode that fixes zero-sized TextViews in Robolec…
…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: 241150766

copybara-robolectric added a commit that referenced this issue Mar 30, 2019

Reintroduce an opt-in mode that fixes zero-sized TextViews in Robolec…
…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: 241150766

copybara-robolectric added a commit that referenced this issue Mar 30, 2019

Reintroduce an opt-in mode that fixes zero-sized TextViews in Robolec…
…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

This comment has been minimized.

Copy link
Contributor Author

commented Apr 12, 2019

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
Projects
None yet
5 participants
You can’t perform that action at this time.