How do you test an Android application across multiple Activities?

前端 未结 14 1609
醉梦人生
醉梦人生 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:35

    I'm working on pretty much the same thing, and I'll probably go with a variation on the accepted answer to this question, but I did come across Calculuon (gitHub) during my searches for a solution.

    0 讨论(0)
  • 2020-12-07 08:36

    Try the Monkey tool testing

    Step 1:

    open the android studio terminal(Tools-> open terminal)

    Step 2:

    In order to use monkey , open up a command prompt and just naviagte to the following directory.

     export PATH=$PATH:/home/adt-bundle-linux-x86-20140702/sdk/platform-tools
    

    Step 3:

    add this monkey command into terminal and press enter..

    see the magic in your emulator.

    adb shell monkey -p com.example.yourpackage -v 500
    

    500- it is the frequency count or the number of events to be sent for testing.

    you can change this count..

    More reference,

    http://www.tutorialspoint.com/android/android_testing.htm

    http://androidtesting.blogspot.in/2012/04/android-testing-with-monkey-tool.html

    0 讨论(0)
  • 2020-12-07 08:39

    There is another way to do the multiple activity using ActivityInstrumentation Class.. Its a normal automation scenario... First get the focus of what ever object you want and then send a key Simple as that sample code

    button.requestFocus();
    sendKeys(KeyEvent.KEYCODE_ENTER);
    

    Only thing is understanding the every API calls will help us.

    0 讨论(0)
  • 2020-12-07 08:40

    I haven't personally used it, but ApplicationTestCase looks like it might be what you're looking for.

    0 讨论(0)
  • 2020-12-07 08:42

    Found this useful with a couple of modifications. Firstly getInstrumentation().waitForIdleSync() will cure the flakiness SingleShot speaks of and also InstrumentationTestCase has a lauchActivity function that can replace the start activity lines.

    0 讨论(0)
  • 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)); 
    
    0 讨论(0)
提交回复
热议问题