Determine fragment change while espresso testing

前端 未结 1 457
难免孤独
难免孤独 2021-01-17 13:32

I\'m testing my application in android composed of 1 main activity and multiple fragments inside in which we navigate.

For my tests I use espresso, and after a click

相关标签:
1条回答
  • 2021-01-17 14:06

    If you really want to do this, you can do

    FragmentManager fragmentManager = getActivity().getFragmentManager()
    

    and get information about the backstack from fragmentManager. If your fragment has a tag, you could assert that findFragmentByTag(tag) returns something non-null.

    But it's normally better to make assertions about the view hierarchy. It's what Espresso was designed for, and it's more in the spirit of black-box testing.

    So I would suggest finding some distinguishing feature of the new fragment, such as the page title if there is one, and asserting that that view is present using the usual Espresso methods, e.g.

    onView(withText("Page Two Title")).check(matches(isDisplayed()));
    
    0 讨论(0)
提交回复
热议问题