Wednesday, February 16, 2011

Android toast notification testing – Android functional testing


A toast notification is a message that pops up on the surface of the window. So the automation test engineers have to test this kind of functional testing.

Robotium 2.1 can support this toast notification testing. Previous Robotoium versions doesn’t support this functional test.

I have found one android service example in the marakana.com site. So you can refer this site and take the source code from the followed link.

This developer has implemented the application with android service with toast notification messages.
Once we can click on Start button that application service the music and it can make one toast notification popup “My Service Created”.



In this source code you can get the MyService.java file. Like the followed code…..

      public void onCreate() {
            Toast.makeText(this, "My Service Created", Toast.LENGTH_LONG).show();
            Log.d(TAG, "onCreate");

            player = MediaPlayer.create(this, R.raw.jals);
            player.setLooping(false); // Set looping
      }

      public void onDestroy() {
            Toast.makeText(this, "My Service Stopped", Toast.LENGTH_LONG).show();
            Log.d(TAG, "onDestroy");
            player.stop();
      }
     
      public void onStart(Intent intent, int startid) {
            Toast.makeText(this, "My Service Started", Toast.LENGTH_LONG).show();
            Log.d(TAG, "onStart");
            player.start();
      }
We have 3 toast notification messages in this example. In this case we need to automate whether this test case is present or not.

Robotium is providing one method solo.searchText(“-----text------”); we need to pass the expected toast text values.This method can be take care of getting toast notification messages in instrumentation.
It can search the toast message and can gives the return type is a Boolean value.


public void testButtonsToast() throws Exception {
             solo.clickOnButton(0);
             boolean toast1 = solo.searchText("My Service Created");
             boolean toast2 = solo.searchText("My Service Started");
             assertEquals("Toast message appered- My service Created",toast1,true);
             assertEquals("Toast message appered- My service Started",toast2,true);
             solo.clickOnButton(1);
             boolean toast3 = solo.searchText("My Service Stopped");
             assertEquals("Toast message appered- My service stopped",toast3,true);                    
      }






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);                 
      }