Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to test in robolectric whether i opened a fragment on button click?

I have a few buttons, on clicking on them i open different dialog fragments. I want to know how to test whether does dialog open ? or if it opens is it of correct type?

Please Help. Thanks in advance.

like image 344
Chirag Jain Avatar asked Nov 11 '14 07:11

Chirag Jain


1 Answers

Well I figure it out by myself. From this very good tutorial by Colin Miller (Sr software engineer @ LinkedIn) i will be able to solve this.

https://www.youtube.com/watch?v=UEklodQTJZY

This question might not be useful but this tutorial is definitely useful.


Solution of this problem is:

button.performClick()

XDialogFragment dialog = (XDialogFragment) activity
                .getFragmentManager().findFragmentByTag(XDialogFragment.TAG);

Assert.assertNotNull(dialog);
like image 186
Chirag Jain Avatar answered Sep 18 '22 11:09

Chirag Jain