How do you test an Android application across multiple Activities?

前端 未结 14 1737
醉梦人生
醉梦人生 2020-12-07 08:01

We are building a complex Android application consisting of many screens and workflows spread across many Activities. Our workflows are similar to what you might see on a Ba

14条回答
  •  执念已碎
    2020-12-07 08:43

    you can do it like this to avoid the flake waiting times out of sync :

    final Button btnLogin = (Button) getActivity().findViewById(R.id.button);
    Instrumentation instrumentation = getInstrumentation();
    
    // Register we are interested in the authentication activity...
    Instrumentation.ActivityMonitor aMonitor = 
            instrumentation.addMonitor(mynextActivity.class.getName(), null, false);
    
    getInstrumentation().runOnMainSync(new Runnable() {
             public void run() {
                 btnLogin.performClick();
             }
         });
    
    getInstrumentation().waitForIdleSync();
    
    //check if we got at least one hit on the new activity
    assertTrue(getInstrumentation().checkMonitorHit(aMonitor, 1)); 
    

提交回复
热议问题