how can you tell when an Android activity is finished loading?

后端 未结 2 1550
小蘑菇
小蘑菇 2020-12-31 04:25

I\'m in the process of working on an automated test suite for our android app, and running into trouble waiting for activities to fully load. I can call getActivity, but ju

2条回答
  •  粉色の甜心
    2020-12-31 05:06

    If you create a setUp() method like this in your test case extending ActivityInstrumentationTestCase2

    @Override
    protected void setUp() throws Exception {
        super.setUp();
    
        final MyActivity activity = getActivity();
    
        tv1 = (EditNumber)activity.findViewById(resId1);
        tv2 = (EditNumber)activity.findViewById(resId2);
    }
    

    your Activity will be fully operational and the layout loaded, demonstrated in this case by the fact that you can access the Views and its content

    @SmallTest
    public void testSimpleCreate() {
        final MyActivity activity = getActivity();
        assertNotNull(activity);
    
        assertNotNull(tv1);
        assertEquals("mystr1", tv1.getText().toString());
        assertNotNull(tv1);
        assertEquals("mystr2", tv2.getText().toString());
    }
    

提交回复
热议问题