Continuing to my last post. Today i want to discuss how to make android apps which are stable, fast and efficient on resources. By now we should understand, mobile platforms are different and need specific tools as well. But whats common is, the need to optimize resource utilization. Again, like for iOS, we discuss the following topics for Android.
Profiling for memory usage
Before you start reading further, i recommend reading abut the instrumentation class in Android documentation and DDMS. DDMS is a great tool provided by android specifically to profile your application and is for our good luck, very nicely integrated in Eclipse.
Feature Testing is usual manual testing. It doesn't require any tools and so is the same as how you do it on Desktop Application or on iOS.
Automation : There are many tools out there to do automation on android. AutoAndroid, SeeTest, Calculon, Robotium and many more may be. This image taken from Vendor Benchmarking depicts nicely the comparison of the first three tools.
I would personally say, Robotium, having used it, is very easy to start with. Being a library so can be imported directly to your project. You can also create a separate test project along side your app. This is the normal way of using it. In order to use it for one click automation, you need it be a totally independent project. And so you need to write a wrapper above Robotium which can be bit of a pain. All the above mentioned 4 automation tools solve different problems and you need to pick one based on your product and your requirement. This goes without saying that all of these are black box testing tools and may or may not require maintenance as you go along developing.
Lets go to profiling, Leaks in your android are hard to find. I couldn't find any useful tool out there to successfully monitor leaks on android. There is no equivalent of Instrument Leaks of iOS for Android. But there are other ways you can try and monitor. Instrumentation class provides us access to the memory usage of your app at any point of time. You just need to make a call and you can get the memory usage. Now using this function you can track the memory usage before and after the code you want to monitor. I understand its hard to find small leaks through this approach but its the best i got. Let me know if you find something better :).
While we are on memory usage. Lets go through memory utilization as well. There are many many ways to get to know your apps memory utilization. DDMS is the easiest, just select the DDMS view and your app from the left side pane. Then there is Instrumentation class, you can use it to track the memory utilization from your code. Then there is another way, your adb shell. You can use many commands to do so, top, dumpsys meminfo proc, procrank, vmstat. There is another tool named smem but you have to separately install it.The tricky part is, once you run the above commands, we get many memory values and its not very clear which one is useful
Pss = proportional set size
Different command line functions would give different outputs.
Because large portions of physical memory are typically shared among multiple applications, the standard measure of memory usage known as resident set size (RSS) will significantly overestimate memory usage. PSS instead measures each application's "fair share" of each shared area to give a realistic measure of the activity of a system during boot. Hence PSS is our best shot for the memory usage by our app. I use procrank as it directly gives me the PSS value. Sometimes if you need more in depth output of dirty pages, you should use dumpsys meminfo.
Profiling for CPU. This is a bad one as i know only one way to do it. Use the top command and see the cpu usage. It works great for me tough because thats all i am looking for :).
Allocations again is something which can be done in multiple ways. I particularly like the DDMS solution for this. You can also use dmtracedump.exe and traceview. Whats good about android allocations is, you can create a dump file for the period you were monitoring your app for, and store it to be viewed later or used later or compared later. its an amazing debugging and testing tool and you should definitely read more about it.
All along the way i have assumed you have the knowledge of what is logcat and how to use it. Its basically a console output of what your device is doing. If you are reading this, you must already understand that for mobile testers, you need to get close to the product from the start and just UI level and feature testing is not enough.
I hope this was helpful. In case i mentioned something wrong or you want to ask anything, drop me a mail at [email protected]