dimanche 3 mai 2015

Prevent android test from closing activity when it's finished

Hello people I'm new to Unit & Instrumentation testing on Android devices.

I wrote a few tests to check for views visibility, text and such. My problem is that after every single test, the activity gets killed. I need to call getActivity() on the beginning of every test in order for them to work.

Is there a way to run a few tests without starting the activity a new every time?

Here is an example of my testing code:

@Override
public void setUp() throws Exception {
    super.setUp();
}


public void testToolbarTitle() throws Exception {
    mActivity = getActivity();
    String title = mActivity.getResources().getString(R.string.my_feed_title);

    String toolbarTitle = ((MainActivity) mActivity).getToolbarTitle();
    Assert.assertNotNull(toolbarTitle);
    Assert.assertEquals(toolbarTitle, title);
}

public void testBoardIconVisible() {
    mActivity = getActivity();

    ImageView drawerIcon = (ImageView) mActivity.findViewById(R.id.toolbar_icon);
    Assert.assertNotNull(drawerIcon);

    Assert.assertEquals(drawerIcon.getVisibility(), ImageView.VISIBLE);
}

Aucun commentaire:

Enregistrer un commentaire