In my activity posted two fragments. In onCreate (), I determine which fragment will be shown.
@Override protected void onCreate(Bundle savedInstanceState) { requestWindowFeature(Window.FEATURE_NO_TITLE); getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN); super.onCreate(savedInstanceState); setContentView(R.layout.activity_login); handleIntent(getIntent()); } private void handleIntent(Intent intent) { LogUtils.d(TAG, "handleIntent action=" + intent.getAction()); if (MainIntentService.ACTION_TARGET_OPENER.equals(intent.getAction())) { loadOpener(); } else if (MainIntentService.ACTION_TARGET_LOGIN.equals(intent.getAction())) { loadLogin(); } else {
loadFragment () takes over the transaction and writes the fragment ...
This is my test class:
@RunWith(AndroidJUnit4.class) @LargeTest public class LoginScreenTest { @Rule public ActivityTestRule<LoginActivity> mNotesActivityTestRule = new ActivityTestRule<>(LoginActivity.class); @Test public void clickAddNoteButton_opensAddNoteUi() throws Exception { onView(withId(R.id.button_login_submit)).perform(click()); onView(withId(R.id.text_login)).check(matches(isDisplayed())); }
}
How can I tell in a test class which fragment should be shown?
source share