Showing posts with label testing. Show all posts
Showing posts with label testing. Show all posts

Wednesday, April 24, 2013

Android - Robolectric - Unit testing request location updates (LocationManager)

Here is the android code to register for network, GPS and passive location updates on activity create

Android Code to test :

To test the above code,
1) First you need to create a mock location
2) Get the ShadowLocationManager using the robolectric's shadowOf method
3) This shadow Object has a method called 'simulateLocation' to mock a location update.
4) Now we can assert the actual value obtained by the listener with the expected value

Robolectric Test :

Sunday, April 14, 2013

Calabash Android - Testing start of an activity

Normally the first test you might write in calabash is to test the start of an activity.
For example consider that your app has a button(with text "Test"), and is configured to call 'launchTestActivity' onClick.

Android code to start the activity :

Now to test this, you need to write the below Calabash feature :