Android Fragment getView() in Robolectric returns null

1,384 views
Skip to first unread message

Henrique Rocha

unread,
Apr 5, 2013, 4:32:26 PM4/5/13
to robol...@googlegroups.com
Hi,

I'm feeling really stupid not being able to test if a Fragment has an EditText, which is supposed to be a very basic thing.
In this project I really want to try test driven development so I'm getting kind of sad.

I've posted my problem at StackOverflow and immediately got negative points for my question, which made me feel even more stupid.

Can you please help me find the source of my problem?


Thanks very much in advance.

deepa bedsur

unread,
Oct 23, 2013, 12:50:47 AM10/23/13
to robol...@googlegroups.com
even i am facing the similar issue.
Did you get any answer for it?

Henrique Rocha

unread,
Oct 23, 2013, 8:37:45 AM10/23/13
to robol...@googlegroups.com
No, I gave up trying to use Robolectric.
I can't make it work for me because I'm using an external library called HoloEverywhere, which apparently doesn't work well with Robolectric.
I'll try Robolectric again once my company drops support for Android 2.x and I don't need HoloEverywhere anymore.


--
You received this message because you are subscribed to the Google Groups "Robolectric" group.
To unsubscribe from this group and stop receiving emails from it, send an email to robolectric...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.



--
Henrique Rocha
Android Developer @ AndroidPIT.de

Erich Douglass

unread,
Oct 23, 2013, 1:17:55 PM10/23/13
to robol...@googlegroups.com
FWIW: A fragment's view doesn't get created until its been attached to an activity.  If you want to test a fragment in isolation, the easiest thing to do is to use FragmentTestUtil.

    MyFragment fragment = new MyFragment();
    FragmentTestUtil.startFragment(fragment);
    assertThat(fragment.getView()).isNotNull();

I can't offer much help with HoloEverywhere as I've never used it before.


Taylor Paul

unread,
Feb 5, 2015, 12:38:08 PM2/5/15
to robol...@googlegroups.com
I tried your method in Roboelectric 2.4 and it still results in a null view... suggestions?
Reply all
Reply to author
Forward
0 new messages