OutOfMemory Exception with Robotium – Update IV

If you are using Robotium for test automation your Android app and you have many test cases that must be executed, you may run into an OutOfMemory Exceptions after a certain time of test execution.
I have this problem with my test suite. The full test suite consists of around 110 test cases. Besides the full test suite I created a smoke test suite that contains about 40 test cases.
On both suites I get the OutOfMemory Exception no matter which device I use for testing. First I thought, I made some mistakes in my tearDown() method or on the general Robotium setup. But this is not the case. If you call the finishOpenedActivities() method in your tearDown() method, not used activities should be removed and the memory of the device should be freed as well.
I searched on the internet and found the reason for this problem on the official Robotium page. There is currently a bug in the finishOpenedActivities() method.

See the commment from Renas Reda:

“The issue here is that we can not break backward compatibility (getOpenedActivities()). Also this is not only a blackbox test framework, people may be interested in getting a hold of the activities that have been opened. Another reason for the Activity references to be kept is due to being able to finish them at the end. That is needed as having a old Activity still open and in focus will lead to complications with the next test case. Many times activities are not cleaned properly and therfore manually calling finish is a must.
Using weak references could work. I will send you a version where Robotium uses weak references to the Activities instead. Please let me know if it works better for you.”

For more information please check the Issue 249 and watch it ;). It looks likes the problem is already solved and I hope the new Robotium release will available in the next days/ weeks!

Drop me a comment, if you have/had similar problems with your Android testing setup using Robotium.

Update 12. June 2012:
Since 11. June 2012 a new Robotium version 3.3 is released. This new version of Robotium fixed the Issue 249, the OutOfMemory Exception in big projects. Besides that some brand new methods are available for testing.

  • takeScreenshot()
  • clickOnActionBarItem(int resourceId)
  • getCurrentImageViews(View parent)

If you want to use the takeScreenshot() method, the application under test need the following permission in the AndroidManifest.xml android.permission.WRITE_EXTERNAL_STORAGE.

Update II: 14.06.2012

Sadly, the OutOfMemory Exception is not yet fixed. The problem still exists. I am already talking to Renas Reda and try to help him fixing the problem. I will inform you when the bug is fixed!

Update III: 02.07.2012

The problem still exist in the current version of Robotium 3.3. I mailed several times with Renas Reda and he doesn’t know why this is happening. For now, as a workaroung I call the garbage collector manually in my tearDown method. My tearDown looks like this:

@Override
public void tearDown() throws Exception {

try {
getActivity().finish();
solo.finishOpenedActivities();
solo = null;
System.gc();

} catch (Throwable e) {
e.printStackTrace();

}
}

At least my full testsuite is now running again, without any Out Of Memory Exceptions.

Update IV: 07. August 2012

A new Robotium version 3.4 is out.
http://code.google.com/p/robotium/. In this release the out of memory exception is fixed! Additionally the Robotium team included some really nice new methods like:

scrollToTop(), scrollToBottom(), scrollListToTop(int index), scrollListToBottom(int index), waitForFragmentById(int id), waitForFragmentByTag(string tag), waitForLogMessage(string logMessage), clickOnActionBarHomeButton(), takeScreenShot(string filename)

Have fun!