Android development and testing

I’m currently taking a course: “Programming Mobile Applications for Android Handheld Systems“. First of all because I am interested in learning about the internals of Android. Secondly, I might want to develop an app someday. Thirdly, I want to find out what testing looks like in app development.
I use the ADT bundle in combination with JDK 6 to work on my assignments. A recent assignment included adding some code to Activities and testing our code to check whether our implementation was correct with JUnit tests making use of Robotium. A simplified code snippet looks like this:

private Solo solo;

// Check for proper counts

solo.searchText("onCreate\\(\\) calls: 1"));
assertTrue("onStart() count was off.",
solo.searchText("onStart\\(\\) calls: 1"));
assertTrue("onResume() count was off.",
solo.searchText("onResume\\(\\) calls: 1"));
assertTrue("onRestart() count was off.",
solo.searchText("onRestart\\(\\) calls: 0"));

// Check for log messages
assertTrue("Log message for 'onCreate()' was not found in Log",
		solo.waitForLogMessage("onCreate", 5));
assertTrue("Log message for 'onStart()' was not found in Log",
		solo.waitForLogMessage("onStart", 5));
assertTrue("Log message for 'onResume()' was not found in Log",
		solo.waitForLogMessage("onResume", 5));

// Clear the log

I am curious to find out more about this test automation framework. If you want to see Robotium in action do this:

  1. Download the ADT bundle
  2. Download the examples and import both (File -> Import -> Android -> Existing Android Code Into WorkSpace)
  3. Create a virtual device and start it; it takes while to start
  4. When the emulator runs, right click on in the ActivityLabTest and select Run as Android JUnit test
Tagged on: , , , ,

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.