Tuesday, February 15, 2011

Android performance testing - Application Launch flow


The followed instrumented code can explains how to calculate the time when application launched for android application performance related testing….

Verify the average time in milli seconds for application launch flow.

You need to pass 2 arguments the Pkg name and Activity name with fully qualified  in followed method
intent.setClassName(Pkg Name, Activity Name)

public void testApplicationLaunchFlow()throws InterruptedException
      {
              long totalTime = 0;
              Intent intent = new Intent();
              intent.setClassName("com.example","com.example.ServicesDemo");
              intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
              intent.setAction(Intent.ACTION_MAIN);
              intent.addCategory(Intent.CATEGORY_LAUNCHER);
              long start_time = System.currentTimeMillis();
              Activity activity = getInstrumentation().startActivitySync(intent);
              long end_time = System.currentTimeMillis();
              long StartupAppTime = end_time - start_time;
              long AverageStartup = 200;
              activity.finish();
              System.out.println("Application is startup" +StartupAppTime+ " in milli seconds");
              assertTrue("must be true ",StartupAppTime > AverageStartup);                 
      }

1 comment:

  1. Could you pls let me know how to instrument the above code with test application

    ReplyDelete