简体   繁体   中英

How to start Fragment directly for espresso test instead of activity

I am running some espresso tests. My problem is instead of opening the Main.activity, i want to open the fragment directly which is part of main activity before starting tests.

You can't. The purpose of fragment is to run alongside Activity. If you want, you can create an empty activity who just run your fragment and his layout, and then put that activity as your MainActivity in the manifest

You can perform a FragmentManager transaction in your test.

If you are using ActivityTestRule in your test it is possible to obtain started activity with getActivity() and then swap or add the fragment the same way it is done in the production code.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM