Saturday, April 20, 2013

Android - Robolectric - Unit testing start of an activity

Here is the android code to start an activity on click of a button

Android Code to test :

To test the above code,
1) First, You can call button's performClick to simulate a click event
2) Now, Get the shadowActivity using the robolectric's shadowOf method
3) This shadow Object has all the methods to test an activity
4) We can get the next started activity's Intent, using the getNextStartedActivity() method and assert it

Robolectric Test :

No comments:

Post a Comment