2

I have to create a test suite to test for any memory leaks occured after doing some operations on my app. So can anyone guide me how to implement it using robotium. I'm able to achieve it a bit but need more help

Test script to find memory leak:

boolean value=Debug.dumpService ("com.apppackage.name", fd, null);
ActivityManager manager=(ActivityManager)getActivity().getSystemService(context.ACTIVITY_SERVICE);
List<RunningAppProcessInfo> service= manager.getRunningAppProcesses();
for(int i=0;i<service.size();i++){
   if (service.get(i).processName.equals("com.apppackage.name"))
              {
                pid=service.get(i).pid;  
          }
          }
android.os.Debug.MemoryInfo[] meminfo=manager.getProcessMemoryInfo (new int []{pid});
Log.d("meminfo",meminfo+"length");
String info = meminfo.toString();

1 Answers1

0

The Solo class that Robotium uses to assist with testing has the method assertMemoryNotLow() which will cause your test to fail when it is invoked if the Android OS considers memory to be low, for example if you create a lot of Bitmaps without recycling them when you're done.

As for fully implementing your suite with Robotium, that kind of open ended question is outside of the scope of Stack Overflow. You can visit this link Getting Started With Robotium to see an example of how Robotium is used. It has a very useful link to download a test project created by the developers which should be enough to get you going. Once you've started, feel free to come back as you encounter challenges and ask some specific questions about the framework; the community will be happy to help. Good Luck!

MattDavis
  • 5,158
  • 2
  • 23
  • 35
  • Additionally, here's a link to another question that may have some useful information for handling memory leaks. http://stackoverflow.com/questions/1147172/what-android-tools-and-methods-work-best-to-find-memory-resource-leaks – MattDavis Jan 16 '13 at 15:46
  • Thanks MattDavis.. I already created bunch of testcases for our app. Now i want to automate something like this. 1. Apply same theme for 10 times. 2. Run some script to find for memory leaks. 3. And get that report. For now I'm able to get memoryInfo objct for a particular app process. I want to get memory allocated info to proceed. Edited my query to include my test script: – Manasa Santosh Jan 17 '13 at 06:28
  • I see your edit. Have you tried running this test script within your Robotium test? What is the specific problem that you're encountering with it? – MattDavis Jan 17 '13 at 16:03
  • I need to get allocated memory for my process. and i dont see any methods to extract that data from memInfo. Actually i dont know how to proceed further(generating report).And i'm not sure whether this approach is right or not. – Manasa Santosh Jan 18 '13 at 10:28