Search code examples
eclipseunit-testinggoogle-mapsjunitandroid-4.0-ice-cream-sandwich

How can I do Junit tests for Google Maps in Android?


I am using the Google Maps API in an Android project and now I need to test it using JUnit if possible. (I am somewhat new to both JUnit and Google Maps.) I have been scouring the internet but was unable to find anything.

The map view has dots/pins for stations and when I tap one I get a balloon popup with the name and other info. Then when I tap the balloon I get a new view with information about the location and actions to perform such as navigate.

What I want to know is, is it possible to write a JUnit test case that finds all these dots/pins, taps them, and verifies information on the new view that pops up? Additionally, I would like to change/mock the location that the GPS has and see what happens if I try to, say navigate overseas or something like that. I do have a list view of the same locations which I will test as well, but I would like to know if there is a way to test the map view.

I would prefer an automated test script like what JUnit provides. If this is not possible with JUnit what is the best alternative?

I am working with Android 4.0 and using Eclipse.

Any help would be greatly appreciated.


Solution

  • In case anyone wants to know after much searching I finally found something that can test Google Maps. Things such as zoom level and I believe tap pin (method is called tapMapMarkerItem()) are supported. I have not tested the pin tap yet tho. Apparently the awesome Robotium does not support map testing by itself. Nicholas Albion was nice enough to create an extension to provides testing support for maps on Android. Thank you so much Nicholas!


    So here it is:
    1. Download the Robotium jars from robotium.org (I found this helpful http://www.vogella.com/articles/AndroidTesting/article.html - by Lars Vogel)
    2. Download the extension from https://github.com/nalbion/robotium-maps